結果
| 問題 | No.430 文字列検索 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-29 22:15:55 |
| 言語 | PyPy3 (8.0.0 + ACL) |
| 結果 |
TLE
不安定
|
| 実行時間 | - |
| コード長 | 860 bytes |
| 記録 | |
| コンパイル時間 | 64 ms |
| コンパイル使用メモリ | 82,160 KB |
| 実行使用メモリ | 86,776 KB |
| 最終ジャッジ日時 | 2026-09-21 17:17:25 |
| 合計ジャッジ時間 | 34,450 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 5 TLE * 9 |
ソースコード
import sys
input = sys.stdin.readline
def make_table(s):
n = len(s)
res = [-1]*(n+1)
j = -1
for i in range(n):
while j>=0 and s[i]!=s[j]:
j = res[j]
j += 1
res[i+1] = j
return res
def kmp(s, w): #s中のwと一致する箇所の先頭インデックスのリストを作成
table = make_table(w)
res = []
m, i, n = 0, 0, len(s)
while m+i<n:
if w[i]==s[m+i]:
i += 1
if i==len(w):
res.append(m)
m = m+i-table[i]
i = table[i]
else:
m = m+i-table[i]
if i>0:
i = table[i]
return res
S = input()[:-1]
M = int(input())
ans = 0
for _ in range(M):
C = input()[:-1]
ans += len(kmp(S, C))
print(ans)