結果

問題 No.78 クジ付きアイスバー
ユーザー mkawa2mkawa2
提出日時 2019-12-18 18:28:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,594 bytes
コンパイル時間 689 ms
コンパイル使用メモリ 10,852 KB
実行使用メモリ 8,292 KB
最終ジャッジ日時 2023-09-21 02:55:02
合計ジャッジ時間 2,709 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,160 KB
testcase_01 AC 16 ms
8,200 KB
testcase_02 AC 16 ms
7,844 KB
testcase_03 AC 16 ms
7,904 KB
testcase_04 AC 16 ms
7,852 KB
testcase_05 AC 17 ms
7,884 KB
testcase_06 AC 16 ms
7,816 KB
testcase_07 AC 16 ms
7,808 KB
testcase_08 AC 17 ms
7,812 KB
testcase_09 AC 17 ms
7,828 KB
testcase_10 AC 16 ms
7,908 KB
testcase_11 AC 16 ms
7,848 KB
testcase_12 AC 16 ms
7,812 KB
testcase_13 AC 16 ms
7,972 KB
testcase_14 AC 16 ms
7,800 KB
testcase_15 AC 16 ms
7,984 KB
testcase_16 AC 17 ms
7,860 KB
testcase_17 AC 16 ms
7,760 KB
testcase_18 AC 16 ms
7,816 KB
testcase_19 AC 16 ms
7,808 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 16 ms
8,220 KB
testcase_24 AC 16 ms
8,136 KB
testcase_25 AC 17 ms
8,176 KB
testcase_26 AC 17 ms
8,292 KB
testcase_27 AC 17 ms
8,220 KB
testcase_28 AC 16 ms
8,188 KB
testcase_29 AC 17 ms
8,268 KB
testcase_30 AC 16 ms
8,208 KB
testcase_31 RE -
testcase_32 RE -
testcase_33 AC 16 ms
7,908 KB
testcase_34 AC 16 ms
7,792 KB
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 AC 16 ms
7,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n, k = MI()
    aa = list(map(int, list(sys.stdin.readline())[:-1]))
    # 最初からi本食べるために買う本数buy[i]
    buy = [0]
    hit = 0  # 当たり本数
    # 最初の2箱分については愚直にシミュレーション
    # 当たりがあればそれを優先的に使う
    # 1箱食べたあとに持っている当たりが0になるときがループの起点
    for i, a in enumerate(aa + aa, 1):
        if hit == 0:
            buy.append(buy[-1] + 1)
        else:
            buy.append(buy[-1])
            hit -= 1
        hit += a
        if i >= n and hit == 0:
            pre_roop = i
    # 食べる本数が2箱以内ならシミュレーションからそのまま回答
    if k <= 2 * n:
        print(buy[k])
        exit()
    # 1箱食べるために買う本数を計算
    buy_for_box = n - sum(aa)
    # 1箱食べるために買う本数が0以下なら1箱以降買う必要はない
    if buy_for_box <= 0:
        print(buy[n])
    # ループ回数、ループ後に必要な本数を求める
    # ループ前とループ後はあわせて、buy[i]から買う本数を求める
    else:
        roop_times, post_roop = divmod(k - pre_roop, n)
        print(roop_times * buy_for_box + buy[pre_roop + post_roop])

main()
0