結果

問題 No.78 クジ付きアイスバー
コンテスト
ユーザー masa
提出日時 2015-02-21 23:33:20
言語 C++11
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 5,000 ms
+ 346µs
コード長 622 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 402 ms
コンパイル使用メモリ 87,100 KB
実行使用メモリ 10,028 KB
最終ジャッジ日時 2026-09-20 23:33:00
合計ジャッジ時間 2,387 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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