結果
| 問題 | No.430 文字列検索 | 
| コンテスト | |
| ユーザー |  convexineq | 
| 提出日時 | 2021-02-04 09:28:03 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 576 bytes | 
| コンパイル時間 | 795 ms | 
| コンパイル使用メモリ | 81,792 KB | 
| 実行使用メモリ | 265,800 KB | 
| 最終ジャッジ日時 | 2024-11-10 00:53:10 | 
| 合計ジャッジ時間 | 4,310 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | -- * 4 | 
| other | AC * 1 TLE * 2 -- * 11 | 
ソースコード
def Z_algorithm(s):
    n = len(s)
    z = [0]*n
    z[0] = n
    i = 1
    j = 0
    while i < n:
        while i+j < n and s[j] == s[i+j]:
            j += 1
        z[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < n and k+z[k] < j:
            z[i+k] = z[k]
            k += 1
        i += k
        j -= k
    return z
#h,w = map(int,input().split())
s = ":"+input()
m = int(input())
ans = 0
ls = len(s)
for _ in range(m):
    t = input()+s
    lt = len(t) - ls
    z = Z_algorithm(t)
    ans += z.count(lt)
print(ans)
            
            
            
        