結果

問題 No.78 クジ付きアイスバー
ユーザー cureskol
提出日時 2020-03-29 15:13:40
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 559 bytes
コンパイル時間 1,644 ms
コンパイル使用メモリ 162,296 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2025-01-02 13:28:59
合計ジャッジ時間 2,888 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long
template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  int n,k;string s;cin>>n>>k>>s;
  int A=0;//1箱目を全部食べるために必要なお金
  int B=0;//1箱目を全部食べた時に浮いたお金
  for(int i=0;i<n;i++){
    if(B==0)A++;
    else B--;
    if(i==k-1)fin(A);
    B+=s[i]-'0';
  }
  if(A<=B)fin(A);
  int ans=0;
  ans+=A+(k/n-1)*(A-B);
  for(int i=0;i<k%n;i++){
    if(B==0)ans++;
    else B--;
    B+=s[i]-'0';
  }
  cout<<ans<<endl;
}
0