結果

問題 No.430 文字列検索
ユーザー tentententen
提出日時 2020-12-25 17:47:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 667 ms / 2,000 ms
コード長 1,212 bytes
コンパイル時間 2,563 ms
コンパイル使用メモリ 81,652 KB
実行使用メモリ 89,300 KB
最終ジャッジ日時 2023-10-23 16:41:29
合計ジャッジ時間 11,271 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 138 ms
57,464 KB
testcase_01 AC 667 ms
89,300 KB
testcase_02 AC 403 ms
66,312 KB
testcase_03 AC 404 ms
66,488 KB
testcase_04 AC 136 ms
57,264 KB
testcase_05 AC 134 ms
57,160 KB
testcase_06 AC 132 ms
57,660 KB
testcase_07 AC 137 ms
57,196 KB
testcase_08 AC 609 ms
86,580 KB
testcase_09 AC 148 ms
57,296 KB
testcase_10 AC 248 ms
62,272 KB
testcase_11 AC 447 ms
68,328 KB
testcase_12 AC 447 ms
68,492 KB
testcase_13 AC 452 ms
68,556 KB
testcase_14 AC 427 ms
68,324 KB
testcase_15 AC 417 ms
66,260 KB
testcase_16 AC 398 ms
64,800 KB
testcase_17 AC 388 ms
66,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] arr = sc.next().toCharArray();
        int length = arr.length;
        long[][] table = new long[10][length];
        for (long[] xx : table) {
            Arrays.fill(xx, -1L);
        }
        HashMap<Long, Integer> map = new HashMap<>();
        for (int i = 0; i < length; i++) {
            table[0][i] = arr[i] - 'A' + 1;
            map.put(table[0][i], map.getOrDefault(table[0][i], 0) + 1);
        }
        for (int i = 1; i < 10; i++) {
            for (int j = 0; j + i < length; j++) {
                table[i][j] = table[i - 1][j] * 27 + table[0][j + i];
                map.put(table[i][j], map.getOrDefault(table[i][j], 0) + 1);
            }
        }
        int m = sc.nextInt();
        int ans = 0;
        for (int i = 0; i < m; i++) {
            ans += map.getOrDefault(getLong(sc.next()), 0);
        }
        System.out.println(ans);
    }
    
    static long getLong(String s) {
        long ans = 0;
        for (char c : s.toCharArray()) {
            ans *= 27;
            ans += c - 'A' + 1;
        }
        return ans;
    }
}
0