結果

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

int main() {
	int n, k;
	string s;

	cin >> n >> k >> s;

	int more = 0;
	for (int i = 0; i < n; i++) {
		more += s[i] - '0';
	}
	int buy_per_box = n - more;
	if (buy_per_box < 0) {
		buy_per_box = 0;
	}

	int n_full = k / n;

	int limit = k % n + (n_full > 0) * n;
	int ans = 0;
	int hit = 0;
	for (int i = 0; i < limit; i++) {
		if (hit > 0) {
			hit--;
		} else {
			ans++;
		}
		hit += s[i % n] - '0';
	}
	if (n_full > 0) {
		ans += buy_per_box * (n_full - 1);
	}
	cout << ans << endl;
	return 0;
}
0