結果

問題 No.78 クジ付きアイスバー
ユーザー IL_mstaIL_msta
提出日時 2015-07-08 08:19:09
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,686 bytes
コンパイル時間 681 ms
コンパイル使用メモリ 84,692 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 05:04:31
合計ジャッジ時間 1,615 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>

#include <algorithm>
#include <cmath>

#include <string>
#include <list>
#include <queue>
#include <vector>
#include <complex>
#include <set>

/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////

int main(void){
    std::cin.tie(0); 
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed;//
    //cout << setprecision(6);//

	int N,K;
	string str;
	cin>>N>>K>>str;

	int Limit=0,ama=0;//1箱を買い切る本数、1箱を越える余り当たり
	int sum=0;//現在までの取得本数
	int kpn = K%N;
	int kpnB = 0;
	bool buy = false;//購入フラグ
	int count = 0;//購入本数
	for(int i=0;i < N;++i){
		if( i+1 > sum){
			++sum;
			++Limit;
			buy = true;
		}else{buy = false;}
		sum += str[i] - '0';
		if(buy == true){++count;}
		if( kpn != 0 && sum >= kpn && kpnB == 0){
			kpnB = count;
		}
	}
	if(N!=1){
		ama = sum%N;
	}else{
		ama = sum - 1;
	}

	if( Limit <= ama ){
		if(K<N){
			P(kpnB);
		}else{
			P(Limit);
		}
	}else if( ama <= 0 ){
		P( K/N * Limit + kpnB );
	}else{
		int ans = 0;
		int nokori ;
		int kuriAma = 0;
		if( K >= 2*N ){
			ans += Limit + (Limit-ama)*(K/N-2);//買う
			//N*(S-1)+ama取得_?
			nokori = N + kpn; 
			kuriAma = ama;
		}else{
			nokori  = K;
			kuriAma = 0;
		}
		int sum2 = kuriAma;
		int count2 = 0;
		for(int i=0; i<2*N;++i){
			if( i+1 > sum2){
				++sum2;
				++count2;
			}
			sum2 += str[i%N] - '0';
			if( sum2 >= nokori ){
				break;
			}
		}
		P(ans + count2);
	}
    return 0;
}
0