結果

問題 No.78 クジ付きアイスバー
ユーザー buey_tbuey_t
提出日時 2023-04-24 13:57:14
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,320 bytes
コンパイル時間 983 ms
コンパイル使用メモリ 87,028 KB
実行使用メモリ 87,792 KB
最終ジャッジ日時 2023-08-08 10:18:42
合計ジャッジ時間 8,801 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 237 ms
82,556 KB
testcase_01 AC 237 ms
82,804 KB
testcase_02 AC 237 ms
82,712 KB
testcase_03 AC 239 ms
82,524 KB
testcase_04 AC 238 ms
82,664 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

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が小さいと全然高速化になってないんだよな
二分探索とか?
何本買うかで二分探索すると
思いつく方法は、まあ買う数さえ決まればあたりの数は容易に計算できる
あたりの数によって変わるものを動的に処理したい
どこから始まるかも大事だし...
'''

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

l = -1
h = K+1

while h-l > 1:
    m = (h+l)//2
    
    cnt = m-m%N
    rem = m%N + atari*(m//N)
    
    while atari*(rem//N) > 0 and cnt < K:
        cnt += rem-rem%N
        rem = atari*(rem//N) + rem%N
        
    
    i = 0
    while rem > 0 and cnt < K:
        if S[i] == '1':
            rem += 1
        elif S[i] == '2':
            rem += 2
        
        rem -= 1
        cnt += 1
        
        i += 1
        
        if i == N:
            i = 0
    
    if cnt >= K:
        h = m
    else:
        l = m

print(h)






0