結果

問題 No.78 クジ付きアイスバー
ユーザー koyumeishikoyumeishi
提出日時 2014-11-26 01:56:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 867 bytes
コンパイル時間 613 ms
コンパイル使用メモリ 60,380 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 12:33:02
合計ジャッジ時間 1,574 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 5 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 6 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 5 ms
5,376 KB
testcase_18 AC 5 ms
5,376 KB
testcase_19 AC 5 ms
5,376 KB
testcase_20 AC 5 ms
5,376 KB
testcase_21 AC 6 ms
5,376 KB
testcase_22 AC 6 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 3 ms
5,376 KB
testcase_31 AC 3 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 3 ms
5,376 KB
testcase_35 AC 4 ms
5,376 KB
testcase_36 AC 5 ms
5,376 KB
testcase_37 AC 6 ms
5,376 KB
testcase_38 AC 6 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
	int n,K;
	string s;
	cin >> n >> K >> s;
	
	int m = (1000/n) * n;
	vector<int> v(m,0);
	for(int i=0; i<m; i++) v[i] = s[i%n] - '0';

	vector<int> dp(m+1, 0);	//当たりをi回分持ち越した場合、何本買うことになるか
	vector<int> next(m+1, 0);	//当たりをi回分持ち越した場合、何回持ち越すことになるか
	
	for(int i=0; i<=m; i++){
		int k=i;
		int t=0;
		for(int j=0; j<m; j++){
			if(k==0) ++t;
			else --k;
			k+=v[j];
		}
		k = min(k, m);
		dp[i] = t;
		next[i] = k;
	}

	int ans = 0;
	int k = 0;

	int x = K/m;
	for(int i=0; i<x; ++i){
		ans += dp[k];
		k = next[k];
	}
	K %= m;
	for(int i=0; i<K; ++i){
		if(k==0) ++ans;
		else --k;
		k += v[i];
	}
	cout << ans << endl;
	return 0;
}
0