結果
| 問題 | 
                            No.1005 BOT対策
                             | 
                    
| コンテスト | |
| ユーザー | 
                             brthyyjp
                         | 
                    
| 提出日時 | 2020-05-02 16:54:51 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 673 bytes | 
| コンパイル時間 | 536 ms | 
| コンパイル使用メモリ | 82,356 KB | 
| 実行使用メモリ | 58,880 KB | 
| 最終ジャッジ日時 | 2024-12-30 13:16:29 | 
| 合計ジャッジ時間 | 2,912 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 23 WA * 4 | 
ソースコード
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)-1
    else:
        i += 1
print(ans)
            
            
            
        
            
brthyyjp