結果

問題 No.430 文字列検索
コンテスト
ユーザー roaris
提出日時 2020-07-29 22:15:55
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
TLE  
実行時間 -
コード長 860 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 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
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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)
0