結果

問題 No.78 クジ付きアイスバー
ユーザー buey_t
提出日時 2023-04-24 12:11:04
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,922 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 90,112 KB
最終ジャッジ日時 2024-11-08 14:11:59
合計ジャッジ時間 23,356 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt,sin,cos,tan,ceil,radians,floor,gcd,exp,log,log10,log2,factorial,fsum
from heapq import heapify, heappop, heappush
from bisect import bisect_left, bisect_right
from copy import deepcopy
import copy
import random
from collections import deque,Counter,defaultdict
from itertools import permutations,combinations
from decimal import Decimal,ROUND_HALF_UP
#tmp = Decimal(mid).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
from functools import lru_cache, reduce
#@lru_cache(maxsize=None)
from operator import add,sub,mul,xor,and_,or_,itemgetter
import sys
input = sys.stdin.readline
# .rstrip()
INF = 10**18
mod1 = 10**9+7
mod2 = 998244353

#DecimalならPython
#再帰ならPython!!!!!!!!!!!!!!!!!!!!!!!!!!


'''
周期性とかかな
ダブリンぐでもいけそうだけど
一周で何本もらえるのか
それで、Kをそれで割ることで、何箱使わないといけないかはわかる
そのあとは愚直でいい

いや、当たりを引き換える必要があるから
周期性が乱れる
一週目だけ特別なのか

当たりくじの数を記録しておいて、当たりくじがアイスバーの長さになるたびにやる
それで結構いい近似を得れる
そして、while now < K+N+atari でやる
'''

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

atari = 0
for i in range(N):
    if S[i] == '1':
        atari += 1
    elif S[i] == '2':
        atari += 2

if atari >= N:
    print(1)
    exit()

now = 0
tmp = 0
cost = 0
while now + tmp + N + atari< K:
    now += N
    cost += N
    tmp += atari
    
    if tmp >= N:
        tmp -= N
        now += N
        tmp += atari

i = 0
while now < K:
    if tmp > 0:
        tmp -= 1
    else:
        cost += 1
    
    if S[i] == '1':
        tmp += 1
    elif S[i] == '2':
        tmp += 2
    
    now += 1
    i += 1
    
    if i == N:
        i = 0
    
print(cost)



















0