結果

問題 No.430 文字列検索
ユーザー convexineqconvexineq
提出日時 2021-02-04 09:28:03
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 576 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 87,068 KB
実行使用メモリ 265,852 KB
最終ジャッジ日時 2023-09-13 04:28:12
合計ジャッジ時間 4,131 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,352 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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