結果

問題 No.78 クジ付きアイスバー
コンテスト
ユーザー DialBird
提出日時 2017-02-22 20:24:12
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 1,108 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,239 ms
コンパイル使用メモリ 180,860 KB
実行使用メモリ 476,456 KB
最終ジャッジ日時 2026-06-04 07:51:49
合計ジャッジ時間 21,696 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 4 TLE * 2 -- * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using namespace std;

#define REP(i,first,last) for (int i=first;i<last;++i)
#define MAX(x,y) (x > y ? x : y)
#define MIN(x,y) (x < y ? x : y)

int N, K;

int main(){
  cin >> N >> K;
  vector<char> ice_box(N);
  REP(i,0,N){
    cin >> ice_box[i];
  }

  queue<int> que;
  int buy = 0;
  int eat = 0;
  int idx = 0;

  while (eat < K) {
    if (que.empty()) {
      switch (ice_box[idx]) {
        case '0':
          idx += 1;
          break;
        case '1':
          que.push(ice_box[(idx + 1) % N]);
          idx += 2;
          break;
        case '2':
          que.push(ice_box[(idx + 1) % N]);
          que.push(ice_box[(idx + 2) % N]);
          idx += 3;
      }
      ++buy;
    } else {
      char ice = que.front();
      que.pop();

      switch (ice) {
        case '0':
          break;
        case '1':
          que.push(ice_box[idx]);
          idx += 1;
          break;
        case '2':
          que.push(ice_box[idx]);
          que.push(ice_box[(idx + 1) % N]);
          idx += 2;
      }
    }

    idx %= N;
    ++eat;
  }

  cout << buy << endl;
}
0