結果

問題 No.78 クジ付きアイスバー
ユーザー eri
提出日時 2015-07-29 00:06:38
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 474 bytes
コンパイル時間 451 ms
コンパイル使用メモリ 57,952 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-08 00:47:07
合計ジャッジ時間 1,589 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#define REP(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long LL;
int main(){
	int n, k; string s;
	cin >> n >> k >> s;

	int at = 0;
	REP(i, n) at += s[i] - '0';

	int wt = max(0, (k - 5000) / n);
	int res = max(0, wt * (n - at));
	at = 0;
	k -= n * wt;

	while (k>0){
		REP(i, n){
			(at > 0) ? at-- : res++;
			--k;
			if (k < 1) break;
			at += s[i] - '0';
		}
	}
	cout << res << endl;
	return 0;
}
0