結果

問題 No.78 クジ付きアイスバー
ユーザー titiatitia
提出日時 2022-01-27 01:23:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,186 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 10,900 KB
実行使用メモリ 8,432 KB
最終ジャッジ日時 2023-08-25 15:04:20
合計ジャッジ時間 2,831 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,260 KB
testcase_01 AC 16 ms
8,372 KB
testcase_02 AC 16 ms
8,224 KB
testcase_03 AC 17 ms
8,256 KB
testcase_04 AC 19 ms
8,256 KB
testcase_05 AC 17 ms
8,188 KB
testcase_06 AC 17 ms
8,232 KB
testcase_07 AC 17 ms
8,172 KB
testcase_08 AC 17 ms
8,348 KB
testcase_09 AC 17 ms
8,300 KB
testcase_10 AC 17 ms
8,232 KB
testcase_11 AC 17 ms
8,316 KB
testcase_12 AC 17 ms
8,176 KB
testcase_13 AC 18 ms
8,264 KB
testcase_14 AC 16 ms
8,180 KB
testcase_15 AC 17 ms
8,256 KB
testcase_16 AC 16 ms
8,268 KB
testcase_17 AC 16 ms
8,172 KB
testcase_18 AC 17 ms
8,364 KB
testcase_19 WA -
testcase_20 AC 17 ms
8,372 KB
testcase_21 AC 17 ms
8,232 KB
testcase_22 WA -
testcase_23 AC 17 ms
8,368 KB
testcase_24 AC 16 ms
8,388 KB
testcase_25 AC 17 ms
8,424 KB
testcase_26 AC 16 ms
8,220 KB
testcase_27 AC 16 ms
8,312 KB
testcase_28 AC 16 ms
8,364 KB
testcase_29 AC 16 ms
8,256 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 16 ms
8,256 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 16 ms
8,260 KB
testcase_37 AC 17 ms
8,368 KB
testcase_38 AC 16 ms
8,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K=map(int,input().split())
S=list(map(int,list(input().strip())))

def calc(x):
    ANS=(x//N)*SUM[-1]
    if x%N>0:
        ANS+=SUM[(x%N)]
    return ANS

SUM=[0]
for s in S:
    SUM.append(SUM[-1]+s)

flag=0
if SUM[-1]>=N:
    flag=1

DP=[0]*(N+1)

for i in range(1,N+1):
    NOW=DP[i-1]
    PLUS=NOW+1

    while True:
        k=calc(PLUS)-calc(NOW)

        NOW=PLUS
        PLUS=PLUS+k

        if PLUS==NOW:
            break

        if flag==1 and PLUS>i+N:
            break

    DP[i]=PLUS

    if DP[i]>=K:
        print(i)
        exit()
    if flag==1 and DP[i]>=i+N:
        print(i)
        exit()

for i in range(N+1):
    if DP[i]>=N:
        ni,nx=i,DP[i]
        break

for i in range(N+1):
    if DP[i]==nx%N:
        bi=i
        break

#print(bi,ni,nx)

rep=(K-nx)//N
ANS=ni+rep*(ni-bi)

rest=(K-nx)%N

#print(ANS,rest)

if rest==0:
    print(ANS)
    exit()

NOW=bi

for i in range(N+1):
    PLUS=NOW+1
    ANS+=1

    while True:
        k=calc(PLUS)-calc(NOW)

        NOW=PLUS
        PLUS=PLUS+k

        if PLUS==NOW:
            break

        if flag==1 and PLUS>i+N:
            break

    if PLUS>=rest:
        print(ANS)
        exit()
    NOW=PLUS
0