結果

問題 No.78 クジ付きアイスバー
ユーザー DialBird
提出日時 2017-02-23 10:37:24
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,115 bytes
コンパイル時間 1,560 ms
コンパイル使用メモリ 157,236 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-01-02 18:14:10
合計ジャッジ時間 2,515 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#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];
  }

  int atari = 0;

  // 一箱目を食べきるのに必要な買う本数
  int first_buy = 0;
  int first_atari = 0;
  REP(i,0,N){
    if (atari > 0) {
      --atari;
    } else {
      ++first_buy;
    }
    atari += ice_box[i] - '0';
  }
  first_atari = atari;

  // 二箱目以降を食べきるのに必要な買う本数
  atari = first_atari;
  int second_buy = 0;
  REP(i,0,N){
    if (atari > 0) {
      --atari;
    } else {
      ++second_buy;
    }
    atari += ice_box[i] - '0';
  }

  // 最後となる
  atari = K < N ? 0 : first_atari;
  int last_buy = 0;

  REP(i,0,K % N){
    if (atari > 0) {
      --atari;
    } else {
      ++last_buy;
    }
    atari += ice_box[i] - '0';
  }

  if (K < N) {
    cout << last_buy << endl;
  } else {
    cout << first_buy + ((K / N) - 1) * second_buy + last_buy << endl;
  }
}
0