結果

問題 No.1005 BOT対策
ユーザー miya145592miya145592
提出日時 2023-05-19 01:39:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 682 bytes
コンパイル時間 520 ms
コンパイル使用メモリ 87,020 KB
実行使用メモリ 75,608 KB
最終ジャッジ日時 2023-08-22 14:40:56
合計ジャッジ時間 3,852 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,252 KB
testcase_01 AC 72 ms
71,276 KB
testcase_02 AC 72 ms
71,316 KB
testcase_03 AC 72 ms
71,528 KB
testcase_04 AC 72 ms
71,532 KB
testcase_05 AC 72 ms
71,580 KB
testcase_06 AC 73 ms
71,216 KB
testcase_07 AC 72 ms
71,324 KB
testcase_08 AC 71 ms
71,344 KB
testcase_09 AC 69 ms
71,016 KB
testcase_10 AC 71 ms
71,264 KB
testcase_11 AC 71 ms
71,456 KB
testcase_12 AC 72 ms
71,348 KB
testcase_13 AC 71 ms
71,132 KB
testcase_14 AC 73 ms
71,460 KB
testcase_15 AC 73 ms
71,508 KB
testcase_16 AC 73 ms
71,208 KB
testcase_17 AC 72 ms
71,308 KB
testcase_18 AC 73 ms
71,132 KB
testcase_19 AC 72 ms
71,152 KB
testcase_20 AC 71 ms
71,272 KB
testcase_21 AC 75 ms
75,292 KB
testcase_22 AC 75 ms
75,608 KB
testcase_23 AC 72 ms
71,152 KB
testcase_24 AC 71 ms
71,136 KB
testcase_25 AC 70 ms
71,548 KB
testcase_26 AC 72 ms
71,304 KB
testcase_27 AC 70 ms
71,296 KB
testcase_28 AC 73 ms
71,432 KB
testcase_29 AC 71 ms
71,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# https://tjkendev.github.io/procon-library/python/string/z-algorithm.html
def z_algo(S):
    N = len(S)
    A = [0]*N
    i = 1; j = 0
    A[0] = l = len(S)
    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A

S = input()
T = input()
z = z_algo(T+S)
cnt = 0
i = len(T)
while i<len(T)+len(S):
    if z[i]>=len(T):
        if len(T)==1:
            print(-1)
            exit()
        cnt += 1
        i+=len(T)-1
    else:
        i+=1
    
print(cnt)
0