結果

問題 No.430 文字列検索
ユーザー 👑 timitimi
提出日時 2022-12-04 21:51:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,476 ms / 2,000 ms
コード長 760 bytes
コンパイル時間 202 ms
コンパイル使用メモリ 82,232 KB
実行使用メモリ 77,440 KB
最終ジャッジ日時 2024-04-20 04:05:42
合計ジャッジ時間 11,705 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
58,112 KB
testcase_01 AC 1,146 ms
77,184 KB
testcase_02 AC 1,476 ms
75,264 KB
testcase_03 AC 959 ms
75,264 KB
testcase_04 AC 39 ms
57,984 KB
testcase_05 AC 37 ms
57,856 KB
testcase_06 AC 40 ms
57,856 KB
testcase_07 AC 36 ms
57,856 KB
testcase_08 AC 49 ms
63,360 KB
testcase_09 AC 40 ms
59,648 KB
testcase_10 AC 46 ms
62,976 KB
testcase_11 AC 962 ms
77,188 KB
testcase_12 AC 967 ms
77,328 KB
testcase_13 AC 981 ms
77,312 KB
testcase_14 AC 974 ms
77,164 KB
testcase_15 AC 964 ms
77,056 KB
testcase_16 AC 972 ms
77,056 KB
testcase_17 AC 986 ms
77,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin, setrecursionlimit
readline = stdin.readline

base = 37; mod = 10**9 + 9
pw = None
def rolling_hash(s):
    l = len(s)
    h = [0]*(l + 1)
    v = 0
    for i in range(l):
        h[i+1] = v = (v * base + ord(s[i])) % mod
    return h
# RH前に、必要な長さの最大値分のpow-tableを計算しておく
def setup_pw(l):
    global pw
    pw = [1]*(l + 1)
    v = 1
    for i in range(l):
        pw[i+1] = v = v * base % mod
def get(h, l, r):
    return (h[r] - h[l] * pw[r-l]) % mod
  
setup_pw(5*10**4)
S=input()
M=int(input())
A=rolling_hash(S)
ans=0
for i in range(M):
  T=input()
  B=rolling_hash(T)[-1]
  for j in range(len(S)-len(T)+1):
    d=get(A,j,j+len(T))
    if d==B:
      ans+=1
    #print(d,j,j+len(T))
print(ans)
0