結果
| 問題 | No.430 文字列検索 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-01-29 18:42:07 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,400 ms / 2,000 ms | 
| コード長 | 680 bytes | 
| コンパイル時間 | 148 ms | 
| コンパイル使用メモリ | 81,988 KB | 
| 実行使用メモリ | 81,740 KB | 
| 最終ジャッジ日時 | 2024-11-10 01:05:22 | 
| 合計ジャッジ時間 | 13,359 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 14 | 
ソースコード
S = input()
N = len(S)
M = int(input())
base = 30
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)
            
            
            
        