結果

問題 No.430 文字列検索
ユーザー Igrmi
提出日時 2021-10-28 02:40:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,806 ms / 2,000 ms
コード長 548 bytes
コンパイル時間 245 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 76,672 KB
最終ジャッジ日時 2024-11-10 00:58:09
合計ジャッジ時間 18,884 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

Base = 1676943010
MOD = 2147483647
S = input()
Q = int(input())
Ans = 0
for _ in range(Q):
    T = input()
    if len(S) < len(T): continue
    SHash = 0
    THash = 0
    B = 1
    for i in range(len(T) - 1, -1, -1):
        SHash += ord(S[i]) * B
        SHash %= MOD
        THash += ord(T[i]) * B
        THash %= MOD
        B *= Base
        B %= MOD
    if SHash == THash: Ans += 1
    for i in range(len(S) - len(T)):
        SHash = ((SHash * Base - ord(S[i]) * B) + ord(S[i + len(T)])) % MOD
        if SHash == THash: Ans += 1
print(Ans)
0