結果

問題 No.430 文字列検索
ユーザー htensaihtensai
提出日時 2019-11-19 21:49:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 604 ms / 2,000 ms
コード長 1,054 bytes
コンパイル時間 2,544 ms
コンパイル使用メモリ 78,276 KB
実行使用メモリ 79,504 KB
最終ジャッジ日時 2024-04-15 01:55:16
合計ジャッジ時間 8,209 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
41,128 KB
testcase_01 AC 604 ms
79,504 KB
testcase_02 AC 310 ms
47,948 KB
testcase_03 AC 340 ms
47,296 KB
testcase_04 AC 126 ms
41,120 KB
testcase_05 AC 126 ms
41,224 KB
testcase_06 AC 127 ms
41,672 KB
testcase_07 AC 128 ms
41,504 KB
testcase_08 AC 563 ms
79,344 KB
testcase_09 AC 135 ms
41,588 KB
testcase_10 AC 199 ms
47,012 KB
testcase_11 AC 407 ms
53,084 KB
testcase_12 AC 398 ms
52,892 KB
testcase_13 AC 391 ms
52,916 KB
testcase_14 AC 381 ms
51,804 KB
testcase_15 AC 360 ms
50,044 KB
testcase_16 AC 356 ms
48,716 KB
testcase_17 AC 332 ms
47,648 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();
		HashMap<Long, Integer>[] maps = new HashMap[10];
		for (int i = 0; i < 10; i++) {
		    maps[i] = new HashMap<Long, Integer>();
		}
		for (int i = 0; i < arr.length; i++) {
		    long code = 0;
		    for (int j = 0; j < 10 && i + j < arr.length; j++) {
		        code *= 26;
		        code += arr[i + j] - 'A';
		        if (maps[j].containsKey(code)) {
		            maps[j].put(code, maps[j].get(code) + 1);
		        } else {
		            maps[j].put(code, 1);
		        }
		    }
		}
		int m = sc.nextInt();
		int ans = 0;
		for (int i = 0; i < m; i++) {
		    char[] tests = sc.next().toCharArray();
		    long code = 0;
		    for (int j = 0; j < tests.length; j++) {
		        code *= 26;
		        code += tests[j] - 'A';
		    }
		    Integer exist = maps[tests.length - 1].get(code);
		    if (exist != null) {
		        ans += exist;
		    }
		}
		System.out.println(ans);
	}
}
0