結果
問題 | No.430 文字列検索 |
ユーザー | tenten |
提出日時 | 2023-12-14 16:24:18 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 415 ms / 2,000 ms |
コード長 | 2,579 bytes |
コンパイル時間 | 2,656 ms |
コンパイル使用メモリ | 85,788 KB |
実行使用メモリ | 89,488 KB |
最終ジャッジ日時 | 2023-12-14 16:24:26 |
合計ジャッジ時間 | 7,202 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 53 ms
53,984 KB |
testcase_01 | AC | 415 ms
89,488 KB |
testcase_02 | AC | 203 ms
65,144 KB |
testcase_03 | AC | 234 ms
65,144 KB |
testcase_04 | AC | 53 ms
53,996 KB |
testcase_05 | AC | 54 ms
53,980 KB |
testcase_06 | AC | 53 ms
53,984 KB |
testcase_07 | AC | 54 ms
54,000 KB |
testcase_08 | AC | 391 ms
86,952 KB |
testcase_09 | AC | 55 ms
53,984 KB |
testcase_10 | AC | 119 ms
60,452 KB |
testcase_11 | AC | 256 ms
68,116 KB |
testcase_12 | AC | 267 ms
67,764 KB |
testcase_13 | AC | 265 ms
67,572 KB |
testcase_14 | AC | 262 ms
65,384 KB |
testcase_15 | AC | 240 ms
64,620 KB |
testcase_16 | AC | 236 ms
64,824 KB |
testcase_17 | AC | 223 ms
64,308 KB |
ソースコード
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(); char[] inputs = sc.next().toCharArray(); int length = inputs.length; long[][] hash = new long[10][length]; ArrayList<HashMap<Long, Integer>> counts = new ArrayList<>(); HashMap<Long, Integer> base = new HashMap<>(); for (int i = 0; i < length; i++) { hash[0][i] = inputs[i] - 'a'; base.put(hash[0][i], base.getOrDefault(hash[0][i], 0) + 1); } counts.add(base); for (int i = 1; i < 10; i++) { HashMap<Long, Integer> tmp = new HashMap<>(); for (int j = 0; j < length - i; j++) { hash[i][j] = hash[i - 1][j] * 26 + hash[0][j + i]; tmp.put(hash[i][j], tmp.getOrDefault(hash[i][j], 0) + 1); } counts.add(tmp); } int m = sc.nextInt(); long ans = 0; while (m-- > 0) { char[] part = sc.next().toCharArray(); long num = 0; for (char c : part) { num *= 26; num += c - 'a'; } ans += counts.get(part.length - 1).getOrDefault(num, 0); } System.out.println(ans); } } 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(); } }