結果

問題 No.1211 円環はお断り
ユーザー mkawa2mkawa2
提出日時 2023-11-08 22:18:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,434 ms / 2,000 ms
コード長 1,533 bytes
コンパイル時間 210 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 104,964 KB
最終ジャッジ日時 2023-11-08 22:19:06
合計ジャッジ時間 20,217 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 38 ms
53,460 KB
testcase_03 AC 38 ms
53,460 KB
testcase_04 AC 37 ms
53,460 KB
testcase_05 AC 40 ms
53,460 KB
testcase_06 AC 37 ms
53,460 KB
testcase_07 AC 44 ms
61,200 KB
testcase_08 AC 38 ms
53,460 KB
testcase_09 AC 50 ms
63,796 KB
testcase_10 AC 45 ms
61,204 KB
testcase_11 AC 49 ms
63,816 KB
testcase_12 AC 42 ms
59,080 KB
testcase_13 AC 475 ms
89,144 KB
testcase_14 AC 497 ms
94,916 KB
testcase_15 AC 387 ms
94,820 KB
testcase_16 AC 949 ms
104,672 KB
testcase_17 AC 93 ms
76,040 KB
testcase_18 AC 400 ms
92,292 KB
testcase_19 AC 143 ms
76,184 KB
testcase_20 AC 113 ms
76,600 KB
testcase_21 AC 151 ms
76,720 KB
testcase_22 AC 487 ms
90,092 KB
testcase_23 AC 597 ms
92,476 KB
testcase_24 AC 441 ms
83,984 KB
testcase_25 AC 73 ms
75,672 KB
testcase_26 AC 437 ms
96,344 KB
testcase_27 AC 414 ms
84,000 KB
testcase_28 AC 533 ms
96,464 KB
testcase_29 AC 596 ms
92,268 KB
testcase_30 AC 797 ms
97,812 KB
testcase_31 AC 317 ms
82,640 KB
testcase_32 AC 989 ms
101,208 KB
testcase_33 AC 1,356 ms
104,744 KB
testcase_34 AC 1,346 ms
104,740 KB
testcase_35 AC 1,262 ms
104,740 KB
testcase_36 AC 1,434 ms
104,764 KB
testcase_37 AC 1,357 ms
104,752 KB
testcase_38 AC 859 ms
104,784 KB
testcase_39 AC 846 ms
104,964 KB
testcase_40 AC 77 ms
99,700 KB
testcase_41 AC 38 ms
53,460 KB
testcase_42 AC 38 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(1000005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = -1-(-1 << 31)
inf = -1-(-1 << 63)
md = 10**9+7
# md = 998244353

from bisect import *

n, k = LI()
aa = LI()
cs = [0]
for a in aa*2: cs.append(cs[-1]+a)

def binary_search(l, r, minimize):
    if minimize: l -= 1
    else: r += 1
    while l+1 < r:
        m = (l+r)//2
        if ok(m) ^ minimize: l = m
        else: r = m
    if minimize: return r
    return l

def ok(m):
    l, r = 0, n
    i = 0
    for _ in range(k):
        j = bisect_left(cs, cs[i]+m)
        if j > n:
            i = j
            break
        if j-i < r-l: l, r = i, j
        i = j
    if i <= n: return True
    for si in range(l+1, r+1):
        i = si
        for _ in range(k):
            i = bisect_left(cs, cs[i]+m)
            if i > si+n: break
        if i <= si+n: return True
    return False

print(binary_search(1, sum(aa)//k, False))
0