結果

問題 No.78 クジ付きアイスバー
ユーザー tmentaikotmentaiko
提出日時 2020-08-27 23:17:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 32 ms / 5,000 ms
コード長 1,076 bytes
コンパイル時間 99 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-26 06:08:39
合計ジャッジ時間 2,381 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
11,008 KB
testcase_01 AC 31 ms
11,008 KB
testcase_02 AC 28 ms
11,008 KB
testcase_03 AC 28 ms
10,880 KB
testcase_04 AC 27 ms
10,880 KB
testcase_05 AC 28 ms
10,880 KB
testcase_06 AC 28 ms
11,008 KB
testcase_07 AC 29 ms
10,880 KB
testcase_08 AC 29 ms
10,880 KB
testcase_09 AC 29 ms
10,880 KB
testcase_10 AC 27 ms
10,880 KB
testcase_11 AC 29 ms
10,880 KB
testcase_12 AC 29 ms
11,008 KB
testcase_13 AC 29 ms
11,008 KB
testcase_14 AC 32 ms
10,880 KB
testcase_15 AC 29 ms
11,008 KB
testcase_16 AC 30 ms
11,008 KB
testcase_17 AC 28 ms
10,880 KB
testcase_18 AC 30 ms
10,880 KB
testcase_19 AC 29 ms
11,008 KB
testcase_20 AC 30 ms
10,880 KB
testcase_21 AC 29 ms
11,008 KB
testcase_22 AC 28 ms
10,880 KB
testcase_23 AC 28 ms
10,880 KB
testcase_24 AC 28 ms
10,880 KB
testcase_25 AC 29 ms
11,008 KB
testcase_26 AC 28 ms
10,880 KB
testcase_27 AC 29 ms
10,880 KB
testcase_28 AC 28 ms
10,880 KB
testcase_29 AC 30 ms
11,008 KB
testcase_30 AC 29 ms
10,880 KB
testcase_31 AC 29 ms
10,880 KB
testcase_32 AC 29 ms
11,008 KB
testcase_33 AC 30 ms
11,008 KB
testcase_34 AC 30 ms
10,880 KB
testcase_35 AC 30 ms
11,008 KB
testcase_36 AC 29 ms
10,880 KB
testcase_37 AC 29 ms
11,008 KB
testcase_38 AC 29 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k= map(int,input().split())
s=input()
c,z=[0]*n,[0]*n
for i in range(n):
    if i==0:c[i],z[i]=1,int(s[i])
    else:
        at=int(s[i])
        if z[i-1]==0:c[i],z[i]=1,at
        else:c[i],z[i]=0,z[i-1]+(at-1)
if k<=n:
    cost1 =[0]*n
    for i in range(n):cost1[i]=c[i]+(0 if i==0 else cost1[i-1])
    print(cost1[k-1])
else:
    c2,z2=[0]*n,[0]*n
    for i in range(n):
        at=int(s[i])
        if i==0:
            if z[-1]>0:c2[i],z2[i]=0,at+z[-1]-1
            else:      c2[i],z2[i]=1,at
        else:
            if z2[i-1]==0:c2[i],z2[i]=1,z2[i-1]+ at
            else:         c2[i],z2[i]=0,z2[i-1]+(at-1)
    if sum(c2)==0 and z2[-1]>0:print(sum(c))
    else:
        b=k//n
        e=k%n
        cost2 =[0]*n
        for i in range(n):
            cost2[i]=c2[i] + (0 if i==0 else cost2[i-1])
        if sum(c2)==0 and z2[-1]>0:
            print(sum(c))
        else:
            goukei=0
            goukei+=sum(c)
            goukei+=0 if b==1 else (b-1)*(sum(c2))
            if e==0:pass
            else:goukei+=cost2[e-1]
            print(goukei)
0