結果

問題 No.430 文字列検索
ユーザー IgrmiIgrmi
提出日時 2021-10-28 02:06:38
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 714 bytes
コンパイル時間 252 ms
コンパイル使用メモリ 82,248 KB
実行使用メモリ 82,908 KB
最終ジャッジ日時 2024-04-16 12:54:21
合計ジャッジ時間 3,793 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
59,672 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

class rollinghash:
    def __init__(self, S, Base = 1676943010, MOD = 2147483647):
        self.Base = Base
        self.MOD = MOD
        N = len(S)
        self.Dat = [0] * (N + 1)
        B = 1
        for i in range(N):
            self.Dat[i + 1] = (self.Dat[i] + ord(S[i]) * B) % MOD
            B *= Base
            B %= MOD
        
    def hash(self, L, R):
        return (self.Dat[R] - self.Dat[L]) * pow(self.Base, self.MOD - L - 1, self.MOD) % self.MOD

S = input()
SHash = rollinghash(S)

Q = int(input())
Ans = 0
for _ in range(Q):
    T = input()
    THash = rollinghash(T).hash(0, len(T))
    for L in range(len(S) - len(T) + 1):
        if SHash.hash(L, L + len(T)) == THash: Ans += 1
print(Ans)
0