結果

問題 No.1005 BOT対策
ユーザー lam6er
提出日時 2025-04-16 15:21:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 705 bytes
コンパイル時間 1,403 ms
コンパイル使用メモリ 81,848 KB
実行使用メモリ 54,156 KB
最終ジャッジ日時 2025-06-20 02:36:02
合計ジャッジ時間 2,420 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input().strip()
T = input().strip()

if len(T) == 1:
    if T in S:
        print(-1)
    else:
        print(0)
else:
    len_T = len(T)
    occurrences = []
    for i in range(len(S) - len_T + 1):
        if S[i:i+len_T] == T:
            occurrences.append(i)
    
    if not occurrences:
        print(0)
    else:
        intervals = []
        for s in occurrences:
            end = s + len_T - 2
            intervals.append((s, end))
        
        intervals.sort(key=lambda x: x[1])
        count = 0
        last_end = -1
        
        for start, end in intervals:
            if start > last_end:
                count += 1
                last_end = end
        
        print(count)
0