結果

問題 No.78 クジ付きアイスバー
ユーザー beet
提出日時 2019-03-23 17:38:26
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 918 bytes
コンパイル時間 1,715 ms
コンパイル使用メモリ 192,908 KB
最終ジャッジ日時 2025-01-07 00:26:30
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,k;
  cin>>n>>k;
  string s;
  cin>>s;

  Int d=0;
  for(char c:s) d+=c-'0';
  auto check=
    [&](Int x)->Int{
      if(n<=d){
        if(n<=x) return 1;
        Int y=x;
        for(Int i=0;i<n;i++){
          if(y==0) return i>=k;
          y--;
          y+=s[i]-'0';
        }
        return 1;
      }
      Int t=(x-d)/(n-d);
      Int cnt=n*t;
      Int res=(x+d*t)-cnt;
      while(cnt<k){
        if(res==0) break;
        res--;        
        res+=s[cnt%n]-'0';
        cnt++;
      }
      return cnt>=k;
    };
  
  Int l=0,r=k;
  while(l+1<r){
    Int m=(l+r)>>1;
    if(check(m)) r=m;
    else l=m;
  }
  cout<<r<<endl;
  return 0;
}
0