結果
問題 | No.430 文字列検索 |
ユーザー | hermione17 |
提出日時 | 2016-10-03 00:11:43 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 757 ms / 2,000 ms |
コード長 | 1,157 bytes |
コンパイル時間 | 4,733 ms |
コンパイル使用メモリ | 79,704 KB |
実行使用メモリ | 82,524 KB |
最終ジャッジ日時 | 2024-05-03 04:27:46 |
合計ジャッジ時間 | 11,875 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 137 ms
54,012 KB |
testcase_01 | AC | 757 ms
82,524 KB |
testcase_02 | AC | 437 ms
48,296 KB |
testcase_03 | AC | 454 ms
48,236 KB |
testcase_04 | AC | 129 ms
41,232 KB |
testcase_05 | AC | 138 ms
41,316 KB |
testcase_06 | AC | 119 ms
39,928 KB |
testcase_07 | AC | 130 ms
41,760 KB |
testcase_08 | AC | 722 ms
79,168 KB |
testcase_09 | AC | 150 ms
41,672 KB |
testcase_10 | AC | 222 ms
46,588 KB |
testcase_11 | AC | 539 ms
52,744 KB |
testcase_12 | AC | 550 ms
52,724 KB |
testcase_13 | AC | 570 ms
52,604 KB |
testcase_14 | AC | 503 ms
51,008 KB |
testcase_15 | AC | 501 ms
50,144 KB |
testcase_16 | AC | 456 ms
48,900 KB |
testcase_17 | AC | 456 ms
48,476 KB |
ソースコード
import java.io.PrintStream; import java.util.HashMap; import java.util.Scanner; public class Y430 { Y430() throws Exception { Scanner in = new Scanner(System.in); PrintStream out = new PrintStream(System.out); String s = in.next(); int m = in.nextInt(); String[] w = new String[m]; for (int i = 0; i < m; i++) { w[i] = in.next(); } HashMap<Long, Integer>[] hashMap = new HashMap[11]; for (int i = 0; i < 11; i++) { hashMap[i] = new HashMap(); } for (int i = 0; i < s.length(); i++) { for (int j = 1; j <= 10 && i + j <= s.length(); j++) { Long x = encode(s.substring(i, i+j)); Integer g = hashMap[j].get(x); if (g == null) g = 0; g += 1; hashMap[j].put(x, g); } } int answer = 0; for (int i = 0; i < m; i++) { Long x = encode(w[i]); Integer g = hashMap[w[i].length()].get(x); if (g != null) answer += g; } out.println(answer); } long encode(String s) { long x = 0; for (int i = 0; i < s.length(); i++) { x = x * 26 + (int)s.charAt(i) - 'A'; } return x; } public static void main(String argv[]) throws Exception { new Y430(); } }