제출 #583587

#제출 시각아이디문제언어결과실행 시간메모리
583587DylanSmith원형 문자열 (IZhO13_rowords)Java
24 / 100
246 ms33376 KiB
import java.util.*; import java.io.*; public class rowords { public static void main(String[] args) throws IOException { Reader in = new Reader(); PrintWriter out = new PrintWriter(System.out); String s1 = in.next(), s2 = in.next(); int res = Math.min(lis(s1 + s1, s2), lis(s1, s2 + s2)); out.println(res); out.close(); } public static int lis(String s1, String s2) { int[][] dp = new int[s1.length() + 1][s2.length() + 1]; for (int i = 1; i <= s1.length(); i++) { for (int j = 1; j <= s2.length(); j++) { if (s1.charAt(i - 1) == s2.charAt(j - 1)) { dp[i][j] = dp[i - 1][j - 1] + 1; } else { dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]); } } } return dp[s1.length()][s2.length()]; } static class Reader { BufferedInputStream in; public Reader() { in = new BufferedInputStream(System.in); } public String nextLine() throws IOException { int c; StringBuilder sb = new StringBuilder(""); while ((c = in.read()) != '\n') sb.append((char)(c)); return sb.toString(); } public String next() throws IOException { int c; StringBuilder sb = new StringBuilder(""); while ((c = in.read()) != ' ' && c != '\n') sb.append((char)(c)); return sb.toString(); } public int nextInt() throws IOException { return (int)nextLong(); } public long nextLong() throws IOException { int c; long res = 0; boolean start = false, negative = false; while ((c = in.read()) != ' ' && c != '\n' || !start) if (c >= '0' && c <= '9' || c == '-') { start = true; if (c == '-') negative = true; else res = res * 10 + c - '0'; } return res * (negative ? -1 : 1); } } public static void sort(int[] arr) { List<Integer> list = new ArrayList<>(); for (int i : arr) { list.add(i); } Collections.sort(list); for (int i = 0; i < arr.length; i++) { arr[i] = list.get(i); } } }
#Verdict Execution timeMemoryGrader output
Fetching results...