結果

問題 No.430 文字列検索
ユーザー tentententen
提出日時 2023-06-13 19:06:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 482 ms / 2,000 ms
コード長 2,358 bytes
コンパイル時間 2,483 ms
コンパイル使用メモリ 88,644 KB
実行使用メモリ 84,136 KB
最終ジャッジ日時 2023-09-04 05:25:58
合計ジャッジ時間 7,373 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,180 KB
testcase_01 AC 482 ms
84,136 KB
testcase_02 AC 224 ms
60,836 KB
testcase_03 AC 249 ms
61,072 KB
testcase_04 AC 43 ms
49,324 KB
testcase_05 AC 43 ms
49,312 KB
testcase_06 AC 43 ms
49,172 KB
testcase_07 AC 44 ms
49,176 KB
testcase_08 AC 409 ms
84,004 KB
testcase_09 AC 46 ms
49,716 KB
testcase_10 AC 120 ms
56,956 KB
testcase_11 AC 267 ms
63,504 KB
testcase_12 AC 266 ms
64,296 KB
testcase_13 AC 278 ms
63,680 KB
testcase_14 AC 243 ms
61,412 KB
testcase_15 AC 239 ms
62,076 KB
testcase_16 AC 218 ms
60,660 KB
testcase_17 AC 221 ms
61,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
        long[][] values = new long[10][inputs.length];
        HashMap<Long, Integer> counts = new HashMap<>();
        for (int i = 0; i < inputs.length; i++) {
            values[0][i] = inputs[i] - 'A' + 1;
            counts.put(values[0][i], counts.getOrDefault(values[0][i], 0) + 1);
        }
        for (int i = 1; i < 10; i++) {
            for (int j = 0; j + i < inputs.length; j++) {
                values[i][j] = values[i - 1][j] * 27 + values[0][j + i];
                counts.put(values[i][j], counts.getOrDefault(values[i][j], 0) + 1);
            }
        }
        int m = sc.nextInt();
        long ans = 0;
        while (m-- > 0) {
            long v = 0;
            for (char c : sc.next().toCharArray()) {
                v *= 27;
                v += c - 'A' + 1;
            }
            ans += counts.getOrDefault(v, 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();
    }
    
}
0