結果

問題 No.1005 BOT対策
ユーザー osrgy01osrgy01
提出日時 2021-05-27 14:23:09
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 573 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-11-06 08:53:25
合計ジャッジ時間 2,033 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

def z_algo(s):
    n=len(s)
    A=[0]*n
    j=c=0
    for i in range(1,n):
        if i+A[i-c]<c+A[c]:
            A[i]=A[i-c]
        else:
            j=max(0,c+A[c]-i)
            while i+j<n and s[j]==s[i+j]: j+=1
            A[i]=j
            c=i
    A[0]=n
    return A

s,t=input(),input()
i=1;num=len(t);ans=0
check=z_algo(t+s)
if t not in s: print(0);exit()
if len(s)==1 or len(t)==1: print(-1);exit()
while i<len(s+t):
    if check[i]==num:
        ans+=1
        i+=num
    elif check[i]>num:
        ans+=1
        i+=check[i]
    else:
        i+=1
print(ans)
0