結果
問題 | No.2454 Former < Latter |
ユーザー | tenten |
提出日時 | 2023-09-04 13:32:12 |
言語 | Java21 (openjdk 21) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,024 bytes |
コンパイル時間 | 3,708 ms |
コンパイル使用メモリ | 92,948 KB |
実行使用メモリ | 77,960 KB |
最終ジャッジ日時 | 2024-06-22 12:00:09 |
合計ジャッジ時間 | 9,382 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
50,516 KB |
testcase_01 | AC | 57 ms
50,328 KB |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | AC | 193 ms
74,648 KB |
testcase_08 | RE | - |
testcase_09 | AC | 162 ms
63,644 KB |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | AC | 195 ms
71,796 KB |
testcase_16 | AC | 199 ms
77,960 KB |
testcase_17 | AC | 483 ms
62,824 KB |
testcase_18 | AC | 196 ms
56,768 KB |
testcase_19 | AC | 197 ms
74,928 KB |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | AC | 168 ms
59,420 KB |
testcase_23 | RE | - |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int t = sc.nextInt(); StringBuilder sb = new StringBuilder(); while (t-- > 0) { int n = sc.nextInt(); char[] inputs = sc.next().toCharArray(); long[][] hashes = new long[10][n]; for (int i = 0; i < n; i++) { hashes[0][i] = inputs[i] - 'a'; } for (int i = 1; i < 10; i++) { for (int j = 0; j + i < n; j++) { hashes[i][j] = hashes[i - 1][j] * 26 + hashes[0][j + i]; } } int ans = 0; for (int i = 1; i < n; i++) { int left = i; int right = n - i; int idx = 0; boolean decided = false; while (left - idx > 0 && right - idx> 0) { int length = Math.min(10, Math.min(left - idx, right - idx)); if (hashes[length - idx - 1][0 + idx] == hashes[length - idx - 1][i + idx]) { idx += 10; } else if (hashes[length - idx - 1][0 + idx] < hashes[length - idx - 1][i + idx]) { ans++; decided = true; break; } else { decided = true; break; } } if (!decided) { if (left < right) { ans++; } } } sb.append(ans).append("\n"); } System.out.print(sb); } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }