結果

問題 No.78 クジ付きアイスバー
コンテスト
ユーザー fantasiabaetica
提出日時 2018-06-29 14:43:56
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
MLE  
実行時間 -
コード長 762 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 465 ms
コンパイル使用メモリ 76,720 KB
実行使用メモリ 1,304,720 KB
最終ジャッジ日時 2026-03-21 13:21:48
合計ジャッジ時間 1,620 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 1 MLE * 2 -- * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
typedef long long int ll;
using namespace std;

int buy_ice(int k, int *box){
    int cost = 0;
    int free = 0;
    for (int i = 0; i < k; i++){
        int ice = box[i];
        if (free > 0){
            free -= 1;
        } else {
            cost += 1;
        }
        if (ice == 2){
            free += 2;
        } else if (ice == 1){
            free += 1;
        } 
    }
    return cost;
}

int main(){
    ll n, k;
    cin >> n >> k;
    int box[k];
    string ices;
    cin >> ices;
    for (int i = 0; i < n; i++){
        int ice = ices[i] - '0';
        for (int j = 0; i + (n * j) < k; j++){
            box[i + (n * j)] = ice;
        }
    }
    int cost = buy_ice(k, box);
    cout << cost << endl;
    
    return 0;
}
0