結果

問題 No.78 クジ付きアイスバー
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-06-18 11:45:16
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 972 bytes
コンパイル時間 250 ms
コンパイル使用メモリ 87,164 KB
実行使用メモリ 71,396 KB
最終ジャッジ日時 2023-09-04 02:15:41
合計ジャッジ時間 7,909 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,396 KB
testcase_01 AC 69 ms
71,056 KB
testcase_02 AC 70 ms
71,336 KB
testcase_03 AC 69 ms
71,384 KB
testcase_04 TLE -
testcase_05 -- -
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 #

def main0(n,k,s):
  cnt=0
  ans=0
  atari=0
  while cnt<k:
    for x in s:
      if atari:
        atari-=1
      else:
        ans+=1
      atari+=x
      cnt+=1
      if cnt==k:break
  return ans

def main1(n,k,s):
  cnt=0
  ans=0
  atari=0
  for x in s:
    if atari:
      atari-=1
    else:
      ans+=1
    atari+=x
    cnt+=1
    if cnt==k:return ans
  if atari>=ans:return ans
  d={}
  cnt=0
  ans=0
  atari=0
  while True:
    for i in range(n):
      x=s[i]
      if atari:
        atari-=1
      else:
        ans+=1
      atari+=x
      cnt+=1
      if cnt==k:return ans
      if (i,atari) in d:
        cnt0,ans0=d[(i,atari)]
        dcnt=cnt-cnt0
        dans=ans-ans0
        loopcnt=(k-cnt)//dcnt
        ans+=loopcnt*dans
        cnt+=loopcnt*dcnt
      else:
        d[(i,atari)]=cnt,ans

if __name__=='__main__':
  n,k=map(int,input().split())
  s=list(map(int,list(input())))
  #ret0=main0(n,k,s)
  ret1=main1(n,k,s)
  print(ret1)
  #print(ret0,ret1)

0