結果

問題 No.78 クジ付きアイスバー
ユーザー H20
提出日時 2021-06-16 10:09:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 44 ms / 5,000 ms
コード長 564 bytes
コンパイル時間 987 ms
コンパイル使用メモリ 82,460 KB
実行使用メモリ 52,224 KB
最終ジャッジ日時 2024-12-29 23:11:58
合計ジャッジ時間 4,731 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K = map(int,input().split())
S = list(input())
temp = 0
for i in range(N):
    if S[i]=='2':
        S[i]='1'
        temp+=1
    elif S[i]=='0' and temp>0:
        S[i]='1'
        temp-=1
if K==1:
    print(1)
elif N==1:
    if S[0]=='0':
        print(K)
    else:
        print(1)
elif N<K:
    ans=1
    ans+=S.count('0')
    for i in range(N):
        if S[i]=='0' and temp>0:
            S[i]='1'
            temp-=1
    K-=N+1
    ans+=(K//N)*S.count('0')
    if K%N>0:
        ans+=S[:K%N].count('0')
    print(ans)
else:
    print(1+S[:K-1].count('0'))
0