結果

問題 No.78 クジ付きアイスバー
ユーザー adothadoth
提出日時 2017-11-17 21:39:06
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 876 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-11-25 08:53:07
合計ジャッジ時間 2,432 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

# https://yukicoder.me/problems/no/78


def data_input():
    N, K = map(int, input().split())
    S = [int(i) for i in input()]
    return N, K, S


def buy_box(ice_box, buy=0, hit=0):
    for ice in ice_box:
        if hit > 0:
            hit -= 1
        else:
            buy += 1
        hit += ice
    return buy, hit


def main():
    box_len, full, ice_box = data_input()

    if box_len >= full:  # 1箱で足りる
        print(buy_box(ice_box[:full])[0])

    else:
        buy, hit = buy_box(ice_box)
        if hit >= box_len:  # 今後買う必要なし
            print(buy)
        else:  # hitの数買わず、繰り返して最後調整
            need_box = full // box_len
            last_ice = full % box_len
            buy += (buy_box(ice_box, hit=hit)[0] * (need_box - 1) + buy_box(ice_box[:last_ice], hit=hit)[0])
            print(buy)

main()
0