結果

問題 No.430 文字列検索
ユーザー tentententen
提出日時 2023-05-08 11:14:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 514 ms / 2,000 ms
コード長 2,595 bytes
コンパイル時間 2,897 ms
コンパイル使用メモリ 93,828 KB
実行使用メモリ 74,776 KB
最終ジャッジ日時 2024-05-03 23:42:34
合計ジャッジ時間 7,771 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
37,204 KB
testcase_01 AC 514 ms
74,776 KB
testcase_02 AC 217 ms
49,572 KB
testcase_03 AC 241 ms
50,000 KB
testcase_04 AC 58 ms
37,284 KB
testcase_05 AC 55 ms
37,092 KB
testcase_06 AC 55 ms
36,644 KB
testcase_07 AC 55 ms
36,988 KB
testcase_08 AC 434 ms
73,184 KB
testcase_09 AC 56 ms
36,900 KB
testcase_10 AC 134 ms
44,916 KB
testcase_11 AC 330 ms
53,972 KB
testcase_12 AC 336 ms
53,772 KB
testcase_13 AC 343 ms
53,972 KB
testcase_14 AC 324 ms
52,020 KB
testcase_15 AC 275 ms
51,648 KB
testcase_16 AC 246 ms
50,328 KB
testcase_17 AC 271 ms
50,488 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();
        int length = inputs.length;
        long[][] values = new long[10][length];
        ArrayList<HashMap<Long, Integer>> counts = new ArrayList<>();
        counts.add(new HashMap<>());
        for (int i = 0; i < length; i++) {
            values[0][i] = inputs[i] - 'A';
            counts.get(0).put(values[0][i], counts.get(0).getOrDefault(values[0][i], 0) + 1);
        }
        for (int i = 1; i < 10; i++) {
            counts.add(new HashMap<>());
            for (int j = 0; j + i < length; j++) {
                values[i][j] = values[i - 1][j] * 26 + values[0][j + i];
                counts.get(i).put(values[i][j], counts.get(i).getOrDefault(values[i][j], 0) + 1);
            }
        }
        int m = sc.nextInt();
        long ans = 0;
        while(m-- > 0) {
            char[] current = sc.next().toCharArray();
            int size = current.length;
            long v = 0;
            for (int i = 0; i < size; i++) {
                v *= 26;
                v += current[i] - 'A';
            }
            ans += counts.get(size - 1).getOrDefault(v, 0);
        }
        System.out.print(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