結果
| 問題 | No.1211 円環はお断り |
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 16:41:03 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,554 bytes |
| 記録 | |
| コンパイル時間 | 192 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 62,592 KB |
| 最終ジャッジ日時 | 2025-06-12 16:41:14 |
| 合計ジャッジ時間 | 4,732 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 2 |
| other | AC * 13 TLE * 1 -- * 27 |
ソースコード
def main():
import sys
input = sys.stdin.read
data = input().split()
N = int(data[0])
K = int(data[1])
A = list(map(int, data[2:2+N]))
if K == 1:
print(sum(A))
return
B = A + A
prefix = [0] * (2 * N + 1)
for i in range(2 * N):
prefix[i+1] = prefix[i] + B[i]
total = sum(A)
low = 0
high = total // K
ans = 0
while low <= high:
mid = (low + high) // 2
if mid == 0:
ans = mid
low = mid + 1
continue
if total < K * mid:
high = mid - 1
continue
next_j = [0] * (2 * N)
right = 0
for i in range(2 * N):
while right < 2 * N and prefix[right + 1] - prefix[i] < mid:
right += 1
if right >= 2 * N:
next_j[i] = 2 * N
else:
next_j[i] = right
found = False
for s in range(N):
current = s
count = 0
end = s + N - 1
while current <= end:
if next_j[current] > end:
break
count += 1
if count >= K:
found = True
break
current = next_j[current] + 1
if found:
break
if found:
ans = mid
low = mid + 1
else:
high = mid - 1
print(ans)
if __name__ == '__main__':
main()
gew1fw