From eba0bb3bd6c4f7044804bbd4c95f5ddf39c9645c Mon Sep 17 00:00:00 2001 From: oncsr Date: Thu, 10 Apr 2025 15:15:33 +0900 Subject: [PATCH] =?UTF-8?q?[20250410]=20BOJ=20/=20P2=20/=20=EC=B5=9C?= =?UTF-8?q?=EB=8C=80=20=EB=AC=B8=EC=9E=90=EC=97=B4=20=EB=B6=99=EC=97=AC?= =?UTF-8?q?=EB=84=A3=EA=B8=B0=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...31\354\227\254\353\204\243\352\270\260.md" | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 "khj20006/202504/10 BOJ P2 \354\265\234\353\214\200 \353\254\270\354\236\220\354\227\264 \353\266\231\354\227\254\353\204\243\352\270\260.md" diff --git "a/khj20006/202504/10 BOJ P2 \354\265\234\353\214\200 \353\254\270\354\236\220\354\227\264 \353\266\231\354\227\254\353\204\243\352\270\260.md" "b/khj20006/202504/10 BOJ P2 \354\265\234\353\214\200 \353\254\270\354\236\220\354\227\264 \353\266\231\354\227\254\353\204\243\352\270\260.md" new file mode 100644 index 00000000..9e01f804 --- /dev/null +++ "b/khj20006/202504/10 BOJ P2 \354\265\234\353\214\200 \353\254\270\354\236\220\354\227\264 \353\266\231\354\227\254\353\204\243\352\270\260.md" @@ -0,0 +1,84 @@ +```java + +import java.util.*; +import java.io.*; + +class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st = new StringTokenizer(""); + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static String nextToken() throws Exception { + while(!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + static int nextInt() throws Exception { return Integer.parseInt(nextToken()); } + static long nextLong() throws Exception { return Long.parseLong(nextToken()); } + static double nextDouble() throws Exception { return Double.parseDouble(nextToken()); } + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + + static int M; + static char[] T; + static char[][] P; + static int[][] X; + static int[] dp; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + T = nextToken().toCharArray(); + dp = new int[T.length]; + M = nextInt(); + P = new char[M][]; + X = new int[M][]; + for(int i=0;i0 && P[i][X[i][j]] != P[i][j]) X[i][j] = X[i][X[i][j]-1]; + if(P[i][X[i][j]] == P[i][j]) X[i][j]++; + } + } + + int[] idx = new int[M]; + for(int i=0;i0 && P[j][idx[j]] != T[i]) idx[j] = X[j][idx[j]-1]; + if(P[j][idx[j]] == T[i]) idx[j]++; + if(idx[j] == P[j].length) { + int res = (i >= P[j].length ? dp[i-P[j].length] : 0) + P[j].length; + dp[i] = Math.max(dp[i], res); + idx[j] = X[j][idx[j]-1]; + } + } + if(i>0) dp[i] = Math.max(dp[i], dp[i-1]); + } + + bw.write(dp[T.length-1] + "\n"); + + } + +} + +```