結果

問題 No.1005 BOT対策
ユーザー lam6er
提出日時 2025-04-15 20:49:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 705 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 82,476 KB
実行使用メモリ 54,336 KB
最終ジャッジ日時 2025-06-20 02:35:27
合計ジャッジ時間 2,271 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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