結果

問題 No.78 クジ付きアイスバー
ユーザー catuppercatupper
提出日時 2014-11-26 00:49:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 930 bytes
コンパイル時間 680 ms
コンパイル使用メモリ 57,592 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 12:31:43
合計ジャッジ時間 1,533 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

/****************/
//蟻本を読もう!//
/****************/
#define INF (1LL << 44)

typedef long long Int;

Int n, k;
string s;
Int solve(int x){
	int now = x;
	int res = 1;
	int cnt = 500;
	while(res){
		if(cnt-- == 0)return INF;
		res--;
		res += s[x] - '0';
		x++;
		x%=n;
	}
	return (x+n-1-now)%n+1;
}

Int go[33][54];

int main(){
	cin >> n >> k >> s;
	for(int i = 0;i < n;i++){
		go[0][i] = solve(i);
	}	
	for(int i = 1;i < 33;i++){
		for(int j = 0;j < 50;j++){
			Int ne = (go[i-1][j] + j) % n;
			go[i][j] = go[i-1][j] + go[i-1][ne];
			go[i][j] = min(go[i][j], INF);
		}
	}
	
	int res = 0, now = 0;
	for(int i = 32;i >= 0;i--){
		if(k >= go[i][now]){
			k -= go[i][now];
			now += go[i][now];
			now %= n;
			res += 1LL << i;
		}
	}
	if(k)res++;
	cout << res << endl;
	return 0;	
}
0