結果

問題 No.78 クジ付きアイスバー
ユーザー DialBirdDialBird
提出日時 2017-02-23 11:19:10
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 878 bytes
コンパイル時間 1,858 ms
コンパイル使用メモリ 146,196 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 21:19:28
合計ジャッジ時間 2,647 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 WA -
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 WA -
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 WA -
testcase_35 AC 1 ms
4,384 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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 box_buy = 0;
  int box_atari = 0;
  vector<int> necessary_buys(N + 1);

  REP(i,0,N){
    if (box_atari > 0) {
      --box_atari;
    } else {
      ++box_buy;
    }
    necessary_buys[i + 1] = box_buy;
    box_atari += ice_box[i] - '0';
  }

  if (K <= N) {
    cout << necessary_buys[K] << endl;
  } else {
    int interval_buy = MAX(0, box_buy - box_atari);
    int tmp = K % N == 0 ? N : K % N;
    int last_buy = MAX(0, necessary_buys[tmp] - box_atari);
    cout << box_buy + ((K / N) - 1) * interval_buy + last_buy << endl;
  }
}
0