結果

問題 No.430 文字列検索
ユーザー KN711KN711
提出日時 2023-01-29 18:40:01
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 681 bytes
コンパイル時間 1,326 ms
コンパイル使用メモリ 87,248 KB
実行使用メモリ 83,180 KB
最終ジャッジ日時 2023-09-12 01:14:55
合計ジャッジ時間 17,186 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,236 KB
testcase_01 WA -
testcase_02 AC 1,517 ms
82,504 KB
testcase_03 AC 1,428 ms
82,596 KB
testcase_04 AC 73 ms
71,140 KB
testcase_05 AC 74 ms
71,456 KB
testcase_06 AC 73 ms
71,408 KB
testcase_07 AC 73 ms
71,276 KB
testcase_08 AC 93 ms
81,396 KB
testcase_09 AC 78 ms
71,352 KB
testcase_10 AC 92 ms
76,132 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 1,523 ms
83,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input()
N = len(S)
M = int(input())

base = 100
MOD = 10**9 + 7

pw = [1]
for i in range(N):
    pw.append(pw[-1]*base % MOD)

hashtable = [0]
for i in range(N):
    hashtable.append((hashtable[-1]*base + ord(S[i])-ord("a"))%MOD)
#print(hashtable)
res = 0
for _ in range(M):
    s = input()
    LEN = len(s)
    if LEN > N:
        continue
    s_hash = [0]
    for i in range(LEN):
        s_hash.append((s_hash[-1]*base + ord(s[i])-ord("a"))%MOD)
    tmp1 = s_hash[-1]
    #print(s,tmp1)
    
    for i in range(N-LEN+1):
        tmp2 = (hashtable[LEN+i] - hashtable[i]*pw[LEN]) % MOD
        if tmp2 == tmp1:
            #print(tmp2,tmp1,i,s)
            res += 1
print(res)
0