結果

問題 No.78 クジ付きアイスバー
コンテスト
ユーザー DialBird
提出日時 2017-03-15 19:27:12
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 97 ms / 5,000 ms
コード長 782 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,318 ms
コンパイル使用メモリ 20,572 KB
実行使用メモリ 15,360 KB
最終ジャッジ日時 2026-03-25 09:24:45
合計ジャッジ時間 5,805 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N, K = [int(i) for i in input().split()]
S = list(input())

# 一箱目
atari = 0
buy = 0
first_box_cnt = []
for ice in S:
    if atari > 0:
        atari -= 1
    else:
        buy += 1

    if ice == '1':
        atari += 1
    elif ice == '2':
        atari += 2
    first_box_cnt.append(buy)

# 二箱目
buy = 0
second_box_cnt = []
for ice in S:
    if atari > 0:
        atari -= 1
    else:
        buy += 1

    if ice == '1':
        atari += 1
    elif ice == '2':
        atari += 2
    second_box_cnt.append(buy)

# Kの大きさで場合分け
if K <= N:
    print(first_box_cnt[K-1])
elif N < K:
    box_cnt = K // N
    res = first_box_cnt[-1]
    res += second_box_cnt[-1] * (box_cnt - 1)
    if K % N != 0:
        res += second_box_cnt[(K % N) - 1]

    print(res)
0