結果
| 問題 | No.430 文字列検索 | 
| コンテスト | |
| ユーザー |  ayaoni | 
| 提出日時 | 2021-05-03 23:25:47 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,369 ms / 2,000 ms | 
| コード長 | 1,023 bytes | 
| コンパイル時間 | 277 ms | 
| コンパイル使用メモリ | 82,432 KB | 
| 実行使用メモリ | 81,792 KB | 
| 最終ジャッジ日時 | 2024-11-10 00:55:22 | 
| 合計ジャッジ時間 | 14,500 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 14 | 
ソースコード
import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())
T = S()
N = len(T)
base = 1234
mod = 10**9+7
AH = [0]
for t in T:
    AH.append((AH[-1]*base+ord(t)) % mod)
base_power = [1]
for _ in range(N):
    base_power.append((base_power[-1]*base) % mod)
def RH(i,j):  # (i,j]
    return (AH[j]-AH[i]*base_power[j-i]) % mod
M = I()
ans = 0
for _ in range(M):
    C = S()
    len_C = len(C)
    if len_C > N:
        continue
    rh = 0
    for i in range(len_C):
        rh += ord(C[i])*base_power[len_C-1-i]
        rh %= mod
    for i in range(N-len_C+1):
        if rh == RH(i,i+len_C):
            ans += 1
print(ans)
            
            
            
        