結果

問題 No.430 文字列検索
ユーザー IgrmiIgrmi
提出日時 2021-10-28 02:40:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,999 ms / 2,000 ms
コード長 548 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 76,416 KB
最終ジャッジ日時 2024-04-16 12:55:32
合計ジャッジ時間 21,143 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
51,968 KB
testcase_01 AC 1,972 ms
70,272 KB
testcase_02 AC 1,966 ms
68,992 KB
testcase_03 AC 1,967 ms
69,248 KB
testcase_04 AC 42 ms
51,712 KB
testcase_05 AC 40 ms
51,712 KB
testcase_06 AC 41 ms
51,968 KB
testcase_07 AC 42 ms
51,968 KB
testcase_08 AC 60 ms
60,544 KB
testcase_09 AC 48 ms
53,504 KB
testcase_10 AC 59 ms
60,416 KB
testcase_11 AC 1,973 ms
70,272 KB
testcase_12 AC 1,971 ms
70,016 KB
testcase_13 AC 1,969 ms
70,272 KB
testcase_14 AC 1,971 ms
70,144 KB
testcase_15 AC 1,972 ms
70,016 KB
testcase_16 AC 1,969 ms
70,144 KB
testcase_17 AC 1,999 ms
76,416 KB
権限があれば一括ダウンロードができます

ソースコード

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