結果

問題 No.1005 BOT対策
ユーザー brthyyjpbrthyyjp
提出日時 2020-05-02 17:00:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 678 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 86,776 KB
実行使用メモリ 74,988 KB
最終ジャッジ日時 2023-08-28 23:02:59
合計ジャッジ時間 4,062 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
70,892 KB
testcase_01 AC 72 ms
71,020 KB
testcase_02 AC 72 ms
71,084 KB
testcase_03 AC 73 ms
71,024 KB
testcase_04 AC 73 ms
71,132 KB
testcase_05 AC 73 ms
71,052 KB
testcase_06 AC 74 ms
71,032 KB
testcase_07 AC 73 ms
70,620 KB
testcase_08 AC 71 ms
70,660 KB
testcase_09 AC 74 ms
70,956 KB
testcase_10 AC 72 ms
70,700 KB
testcase_11 AC 74 ms
71,020 KB
testcase_12 AC 76 ms
71,116 KB
testcase_13 AC 75 ms
70,868 KB
testcase_14 AC 76 ms
71,028 KB
testcase_15 AC 73 ms
71,088 KB
testcase_16 AC 73 ms
70,864 KB
testcase_17 AC 72 ms
70,940 KB
testcase_18 AC 73 ms
70,908 KB
testcase_19 AC 73 ms
70,668 KB
testcase_20 AC 72 ms
70,948 KB
testcase_21 AC 77 ms
74,988 KB
testcase_22 AC 75 ms
74,956 KB
testcase_23 AC 72 ms
70,824 KB
testcase_24 AC 73 ms
70,824 KB
testcase_25 AC 74 ms
71,140 KB
testcase_26 AC 73 ms
70,820 KB
testcase_27 AC 73 ms
71,032 KB
testcase_28 AC 74 ms
71,036 KB
testcase_29 AC 70 ms
71,016 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 = len(t)
while i < len(Z):
    if Z[i] >= len(t):
        ans += 1
        i += len(t)-1
    else:
        i += 1

print(ans)
0