結果
問題 |
No.430 文字列検索
|
ユーザー |
|
提出日時 | 2023-01-29 18:40:01 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 681 bytes |
コンパイル時間 | 174 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 81,408 KB |
最終ジャッジ日時 | 2024-11-10 01:05:23 |
合計ジャッジ時間 | 13,121 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 WA * 7 |
ソースコード
S = input() N = len(S) M = int(input()) base = 100 MOD = 10**9 + 7 pw = [1] for i in range(N): pw.append(pw[-1]*base % MOD) hashtable = [0] for i in range(N): hashtable.append((hashtable[-1]*base + ord(S[i])-ord("a"))%MOD) #print(hashtable) res = 0 for _ in range(M): s = input() LEN = len(s) if LEN > N: continue s_hash = [0] for i in range(LEN): s_hash.append((s_hash[-1]*base + ord(s[i])-ord("a"))%MOD) tmp1 = s_hash[-1] #print(s,tmp1) for i in range(N-LEN+1): tmp2 = (hashtable[LEN+i] - hashtable[i]*pw[LEN]) % MOD if tmp2 == tmp1: #print(tmp2,tmp1,i,s) res += 1 print(res)