結果

問題 No.1005 BOT対策
ユーザー brthyyjpbrthyyjp
提出日時 2020-05-02 16:53:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 671 bytes
コンパイル時間 815 ms
コンパイル使用メモリ 86,864 KB
実行使用メモリ 75,828 KB
最終ジャッジ日時 2023-08-28 22:34:40
合計ジャッジ時間 3,829 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
70,932 KB
testcase_01 AC 70 ms
70,968 KB
testcase_02 AC 69 ms
70,692 KB
testcase_03 AC 70 ms
70,876 KB
testcase_04 AC 71 ms
70,968 KB
testcase_05 AC 70 ms
71,156 KB
testcase_06 AC 71 ms
71,056 KB
testcase_07 AC 70 ms
70,968 KB
testcase_08 AC 69 ms
70,916 KB
testcase_09 AC 69 ms
71,272 KB
testcase_10 AC 71 ms
70,888 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 72 ms
71,168 KB
testcase_14 AC 71 ms
70,968 KB
testcase_15 AC 71 ms
71,292 KB
testcase_16 AC 71 ms
71,164 KB
testcase_17 AC 71 ms
71,164 KB
testcase_18 AC 69 ms
70,940 KB
testcase_19 AC 72 ms
71,068 KB
testcase_20 AC 71 ms
71,160 KB
testcase_21 AC 74 ms
75,616 KB
testcase_22 AC 75 ms
75,828 KB
testcase_23 AC 71 ms
71,132 KB
testcase_24 AC 71 ms
71,232 KB
testcase_25 AC 72 ms
71,060 KB
testcase_26 AC 72 ms
71,064 KB
testcase_27 AC 72 ms
71,240 KB
testcase_28 WA -
testcase_29 AC 70 ms
71,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

s = str(input())
t = str(input())

if len(t) == 1:
    if t in set(list(s)):
        print(-1)
    else:
        print(0)
    exit()

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

Z = z_algorithm(t+s)
#print(Z)
ans = 0
i = 1
while i < len(Z):
    if Z[i] >= len(t):
        ans += 1
        i += len(t)
    else:
        i += 1

print(ans)
0