結果

問題 No.78 クジ付きアイスバー
ユーザー itezpace
提出日時 2016-08-04 17:48:38
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 535 bytes
コンパイル時間 537 ms
コンパイル使用メモリ 57,012 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-07 00:03:53
合計ジャッジ時間 1,877 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 9 WA * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
int main(){
  int n,k,a,b,c,d,e,f,g,h,j;
  cin>>n>>k;
  string s;
  cin>>s;
  b=n;
  c=0;
  d=0;
  for(int i=0; i<n; ++i){
    a=s[i]-'0';
    if(d<1){
      c++;
    } else {
      d--;
    }
    if(a>0) d+=a;
  }
  if(b<=d){
    cout<<1<<endl;
    return 0;
  }
  e=k/(b+d);
  f=(b+d)*e;
  g=c*e;
  j=d;
  for(int i=0; i<n; ++i){
    if(f>=k) break;
    h=s[i]-'0';
    f++;
    f+=h;
    if(j<1){
      g++;
    } else {
      j--;
    }
    if(h>0) j+=h;
  }
  cout<<g<<endl;
  return 0;
}
0