結果

問題 No.78 クジ付きアイスバー
ユーザー chlo27chlo27
提出日時 2018-12-20 22:25:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,139 bytes
コンパイル時間 1,789 ms
コンパイル使用メモリ 167,480 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-26 01:13:38
合計ジャッジ時間 3,021 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);++i)
#define rep1(i, n) for(int i=1;i<=(int)(n);++i)
#define irep(i, a, n) for(int i=a;i<(int)(n);++i)
#define rrep(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define rrep1(i, n) for(int i=(int)(n);i>=1;--i)
#define allrep(V, v) for(auto&& V:v)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const int INF=1<<29;
const double EPS=1e-9;
using namespace std;


int main (void)
{
  int n,k; cin>>n>>k;
  string s; cin>>s;
  int buy=0,free=0;
  if(k<=n){
    rep(i,k){
      if(free > 0) --free;
      else ++buy;
      if(s[i] == '1') free+=1;
      if(s[i] == '2') free+=2;
    }
    cout<<buy<<endl;
    return 0;
  }

  rep(i,n){
    if(free > 0) --free;
    else ++buy;
    if(s[i] == '1') free+=1;
    if(s[i] == '2') free+=2;
  }
  if(free>=buy){
    cout<<buy<<endl;
    return 0;
  }

  int onebox_buy=buy,onebox_extra_free=free;
  int boxnum=k/n;
  buy=0;
  rep(i,k%n){
    if(free > 0) --free;
    else ++buy;
    if(s[i] == '1') free+=1;
    if(s[i] == '2') free+=2;
  }

  cout<<onebox_buy+(onebox_buy-onebox_extra_free)*(boxnum-1)+buy<<endl;
  return 0;
}
0