結果
問題 |
No.1211 円環はお断り
|
ユーザー |
![]() |
提出日時 | 2025-06-12 17:09:04 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,573 bytes |
コンパイル時間 | 316 ms |
コンパイル使用メモリ | 82,644 KB |
実行使用メモリ | 93,304 KB |
最終ジャッジ日時 | 2025-06-12 17:09:09 |
合計ジャッジ時間 | 5,212 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 2 |
other | AC * 13 TLE * 1 -- * 27 |
ソースコード
import sys import bisect def main(): N, K = map(int, sys.stdin.readline().split()) A = list(map(int, sys.stdin.readline().split())) sum_A = sum(A) if K == 0: print(0) return if sum_A < K: print(0) return low = 0 high = sum_A // K # 初始猜测,可以更高 ans = 0 while low <= high: mid = (low + high) // 2 # 复制数组 B = A + A # 计算前缀和 pre_sum = [0] * (2 * N + 1) for i in range(1, 2*N+1): pre_sum[i] = pre_sum[i-1] + B[i-1] # 预处理next数组 next_j = [2*N] * (2*N + 1) for i in range(2*N + 1): target = pre_sum[i] + mid # 在[i+1, 2N]中找最小j,使得pre_sum[j] >= target j = bisect.bisect_left(pre_sum, target, i+1, 2*N +1) if j <= 2*N: next_j[i] = j else: next_j[i] = 2*N + 1 # 表示无法分割 # 检查每个窗口 found = False for i in range(N): current = i cnt = 0 while current <= i + N -1: j = next_j[current] if j > i + N: break cnt += 1 if cnt >= K: found = True break current = j if found: break if found: ans = mid low = mid + 1 else: high = mid -1 print(ans) if __name__ == '__main__': main()