結果
問題 | No.430 文字列検索 |
ユーザー | nebukuro09 |
提出日時 | 2016-10-03 11:03:35 |
言語 | Python2 (2.7.18) |
結果 |
AC
|
実行時間 | 463 ms / 2,000 ms |
コード長 | 768 bytes |
コンパイル時間 | 553 ms |
コンパイル使用メモリ | 6,672 KB |
実行使用メモリ | 51,408 KB |
最終ジャッジ日時 | 2023-08-15 17:34:57 |
合計ジャッジ時間 | 6,153 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 10 ms
5,984 KB |
testcase_01 | AC | 463 ms
51,408 KB |
testcase_02 | AC | 418 ms
6,308 KB |
testcase_03 | AC | 423 ms
6,496 KB |
testcase_04 | AC | 10 ms
6,016 KB |
testcase_05 | AC | 9 ms
6,180 KB |
testcase_06 | AC | 9 ms
5,980 KB |
testcase_07 | AC | 11 ms
5,968 KB |
testcase_08 | AC | 444 ms
50,968 KB |
testcase_09 | AC | 10 ms
6,220 KB |
testcase_10 | AC | 47 ms
10,284 KB |
testcase_11 | AC | 420 ms
10,812 KB |
testcase_12 | AC | 421 ms
10,896 KB |
testcase_13 | AC | 426 ms
10,788 KB |
testcase_14 | AC | 425 ms
10,664 KB |
testcase_15 | AC | 425 ms
7,644 KB |
testcase_16 | AC | 431 ms
6,576 KB |
testcase_17 | AC | 426 ms
6,568 KB |
ソースコード
S = raw_input() M = input() C = [raw_input() for _ in xrange(M)] Ch = [] for s in C: h = 0 for i, c in enumerate(s): h += 26**i*(ord(c)-ord('A')+1) Ch.append(h) N = len(S) rolling_hash = {} for n in xrange(1, 11): if n > N: break h = 0 for i in xrange(n): h += 26**i*(ord(S[i])-ord('A')+1) if h in rolling_hash: rolling_hash[h] += 1 else: rolling_hash[h] = 1 for i in xrange(n, N): h -= ord(S[i-n])-ord('A')+1 h /= 26 h += 26**(n-1)*(ord(S[i])-ord('A')+1) if h in rolling_hash: rolling_hash[h] += 1 else: rolling_hash[h] = 1 ans = 0 for c in Ch: if c in rolling_hash: ans += rolling_hash[c] print ans