結果

問題 No.78 クジ付きアイスバー
ユーザー convexineqconvexineq
提出日時 2021-01-17 03:26:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 740 bytes
コンパイル時間 2,057 ms
コンパイル使用メモリ 86,760 KB
実行使用メモリ 76,300 KB
最終ジャッジ日時 2023-08-19 09:24:12
合計ジャッジ時間 8,265 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,484 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 79 ms
75,852 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 69 ms
71,344 KB
testcase_15 AC 67 ms
71,280 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 77 ms
76,212 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 70 ms
71,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k = map(int,input().split())
*s, = map(int,input())
INF = 1000
nxt = [0]*n
val = [0]*n
for i in range(n):
    v = s[i]
    ii = i+1
    while 0 < ii-i < 200:
        v -= 1
        v += s[ii%n]
        ii += 1
    nxt[i] = ii%n
    val[i] = ii-i if v==0 else k+1

nxt = [nxt]
val = [val]
for _ in range(32):
    nn = [nxt[-1][nxt[-1][i]] for i in range(n)]
    nxt.append(nn)
    nn = [val[-1][i] + val[-1][nxt[-1][i]] for i in range(n)]
    val.append(nn)

def check(x): #x回遷移でval>=k?
    v = idx = 0
    for i in range(31):
        if x>>i&1:
            v += val[i][idx]
            idx = nxt[i][idx]
    return v >= k


ng = 0
ok = k
while ok-ng>1:
    mid = (ok+ng)//2
    if check(mid): ok = mid
    else: ng = mid
print(ok)
0