結果

問題 No.1005 BOT対策
ユーザー TnaTna
提出日時 2022-07-27 10:48:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,146 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 10,996 KB
実行使用メモリ 8,572 KB
最終ジャッジ日時 2023-09-23 17:23:06
合計ジャッジ時間 1,844 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,344 KB
testcase_01 AC 17 ms
8,496 KB
testcase_02 WA -
testcase_03 AC 17 ms
8,368 KB
testcase_04 AC 17 ms
8,428 KB
testcase_05 AC 16 ms
8,428 KB
testcase_06 AC 17 ms
8,348 KB
testcase_07 AC 17 ms
8,356 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 17 ms
8,504 KB
testcase_11 AC 17 ms
8,388 KB
testcase_12 AC 18 ms
8,284 KB
testcase_13 AC 18 ms
8,352 KB
testcase_14 AC 17 ms
8,280 KB
testcase_15 AC 17 ms
8,360 KB
testcase_16 AC 16 ms
8,284 KB
testcase_17 AC 18 ms
8,368 KB
testcase_18 WA -
testcase_19 AC 17 ms
8,468 KB
testcase_20 AC 17 ms
8,324 KB
testcase_21 AC 17 ms
8,376 KB
testcase_22 AC 17 ms
8,284 KB
testcase_23 AC 17 ms
8,424 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 17 ms
8,548 KB
testcase_28 AC 18 ms
8,392 KB
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import OrderedDict

S = input()
T = input()
if len(T) == 1:
    print(-1)
    sys.exit()
# cnt = S.count(T)
# if len(T) == 1 and cnt == 0:
#     print(cnt)
# elif len(T) == 1 and cnt != 0:
#     print(-1)
# else:
#     print(cnt)


# Z-algorithm
# https://qiita.com/masayoshi361/items/1be110f13412f5431da2
# https://perogram.hateblo.jp/entry/z_algo_revisit
# https://qiita.com/Pro_ktmr/items/16904c9570aa0953bf05
def Z_algo(S):
    n = len(S)
    LCP = [0]*n
    i = 1
    j = 0
    c = 0   # 最も末尾側までLCPを求めたインデックス
    for i in range(1, n):
        # i番目からのLCPが以前計算したcからのLCPに含まれている場合
        if i+LCP[i-c] < c+LCP[c]:
            LCP[i] = LCP[i-c]
        else:
            j = max(0, c+LCP[c]-i)
            while i+j < n and S[j] == S[i+j]:
                j += 1
            LCP[i] = j
            c = i
    LCP[0] = n
    return LCP


# min_T = "".join(OrderedDict.fromkeys(T))
# print(min_T)

# print(Z_algo(S))
z_results = Z_algo(T+S)
# print(z_results)
results = [x for x in z_results[len(T):] if x >= len(T)]
print(len(results))
0