結果
問題 |
No.1148 土偶Ⅲ
|
ユーザー |
![]() |
提出日時 | 2025-03-20 21:15:14 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 154 ms / 2,000 ms |
コード長 | 695 bytes |
コンパイル時間 | 202 ms |
コンパイル使用メモリ | 82,708 KB |
実行使用メモリ | 85,796 KB |
最終ジャッジ日時 | 2025-03-20 21:15:59 |
合計ジャッジ時間 | 4,121 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
import bisect n, w = map(int, input().split()) a = [int(input()) for _ in range(n)] prefix_sum = [0] * (n + 1) for i in range(n): prefix_sum[i + 1] = prefix_sum[i] + a[i] left = 0 last_occurrence = {} max_length = 0 for right in range(n): current = a[right] if current in last_occurrence and last_occurrence[current] >= left: left = max(left, last_occurrence[current] + 1) last_occurrence[current] = right target = prefix_sum[right + 1] - w k = bisect.bisect_left(prefix_sum, target, left, right + 2) if k <= right: current_length = right - k + 1 if current_length > max_length: max_length = current_length print(max_length)