結果
問題 |
No.1211 円環はお断り
|
ユーザー |
![]() |
提出日時 | 2025-05-14 12:52:28 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,631 bytes |
コンパイル時間 | 384 ms |
コンパイル使用メモリ | 82,584 KB |
実行使用メモリ | 128,384 KB |
最終ジャッジ日時 | 2025-05-14 12:54:21 |
合計ジャッジ時間 | 5,626 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 WA * 5 |
ソースコード
def main(): import sys input = sys.stdin.read().split() N = int(input[0]) K = int(input[1]) A = list(map(int, input[2:2+N])) S = sum(A) if K == 0: print(0) return low = 1 high = S // K if high * K < S: high += 1 answer = 0 def is_possible(M): if S < K * M: return False # Check linear case cnt = 0 current_sum = 0 for num in A: current_sum += num if current_sum >= M: cnt += 1 current_sum = 0 if cnt >= K: return True # Precompute split_counts split_counts = [0] * (N + 1) current_sum = 0 for i in range(N-1, -1, -1): current_sum += A[i] if current_sum >= M: split_counts[i] = split_counts[i+1] + 1 current_sum = 0 else: split_counts[i] = split_counts[i+1] # Precompute prefix sums prefix_sum = [0] * (N + 1) for i in range(N): prefix_sum[i+1] = prefix_sum[i] + A[i] # Check for any i where prefix_sum[i+1] >= M and split_counts[i+1] >= K-1 for i in range(N): if prefix_sum[i+1] >= M and split_counts[i+1] >= K-1: return True return False while low <= high: mid = (low + high) // 2 if is_possible(mid): answer = mid low = mid + 1 else: high = mid - 1 print(answer) if __name__ == "__main__": main()