結果

問題 No.1005 BOT対策
ユーザー lam6er
提出日時 2025-04-15 20:48:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 861 bytes
コンパイル時間 252 ms
コンパイル使用メモリ 82,476 KB
実行使用メモリ 53,860 KB
最終ジャッジ日時 2025-06-20 02:35:22
合計ジャッジ時間 2,658 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

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

m = len(T)
n = len(S)

if m == 1:
    if T in S:
        print(-1)
    else:
        print(0)
else:
    # Find all occurrences of T in S
    occurrences = []
    t_len = len(T)
    for i in range(len(S) - t_len + 1):
        if S[i:i+t_len] == T:
            occurrences.append(i)
    
    if not occurrences:
        print(0)
    else:
        # Generate intervals [i, i + m - 2]
        intervals = []
        for i in occurrences:
            end = i + m - 2
            intervals.append((i, end))
        
        # Sort intervals by their end
        intervals.sort(key=lambda x: x[1])
        
        # Greedy interval covering
        count = 0
        last = -1
        for start, end in intervals:
            if start > last:
                count += 1
                last = end
        
        print(count)
0