結果
| 問題 |
No.1005 BOT対策
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-15 20:50:28 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 47 ms / 2,000 ms |
| コード長 | 861 bytes |
| コンパイル時間 | 257 ms |
| コンパイル使用メモリ | 82,300 KB |
| 実行使用メモリ | 54,728 KB |
| 最終ジャッジ日時 | 2025-06-20 02:35:29 |
| 合計ジャッジ時間 | 2,493 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
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)
lam6er