結果
問題 |
No.430 文字列検索
|
ユーザー |
|
提出日時 | 2016-10-03 11:03:35 |
言語 | Python2 (2.7.18) |
結果 |
AC
|
実行時間 | 512 ms / 2,000 ms |
コード長 | 768 bytes |
コンパイル時間 | 249 ms |
コンパイル使用メモリ | 6,912 KB |
実行使用メモリ | 51,948 KB |
最終ジャッジ日時 | 2024-11-10 00:08:20 |
合計ジャッジ時間 | 5,721 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 14 |
ソースコード
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