結果
| 問題 |
No.78 クジ付きアイスバー
|
| コンテスト | |
| ユーザー |
kei
|
| 提出日時 | 2018-04-27 01:10:44 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 3,301 bytes |
| コンパイル時間 | 1,599 ms |
| コンパイル使用メモリ | 169,788 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-27 21:30:26 |
| 合計ジャッジ時間 | 3,030 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 35 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
/*
<url:https://yukicoder.me/problems/no/78>
問題文============================================================
A君は当たりクジ付きのアイスバーが大好きである。
アイスバーには「ハズレ」と「1本当たり」と「2本当たり」がある。
ハズレは何ももらえないが、当たりだとその本数をタダでもらえる。
お店ではアイスバーが箱詰めされて売られている。
1つの箱にはN本のアイスバーが入っている。
A君は箱の先頭から順にしかアイスバーを取り出すことはできない。
買う場合も当たりと引き換えの場合もこの箱からアイスバーを取り出す。
1つの箱の中のハズレと当たりクジの配置はどの箱も同じである。
お店には1つのアイスバーの箱があり、売り切れると1つの新しい箱を補充する。
いまお店には新しい手つかずのアイスバーの箱がある。
A君は最初は「当たり」クジを持っておらず予算は無限にある。
K本のアイスバーを食べるためにはA君は最低何本のアイスを買う必要があるか?
=================================================================
解説=============================================================
================================================================
*/
ll solve(){
ll res = 0;
ll N,K; cin >> N >> K;
string S; cin >> S;
for(auto& c:S) c -= '0';
ll sum = 0;
ll a = 0;
ll b = 0;
vector<pll> memo(3*N);
for(int i = 0; i < 3*N;i++){
memo[i] = pll(a,b);
if(a){
a--;
}else{
b++;
}
a += S[i%N];
sum++;
if(sum >= K){ return res = b; }
}
// cout << memo << endl;
if(a>=b) return res = b;
for(int i = 1; i <= N;i++){
if((memo[i].first + memo[i+N].first)!=0)continue;
//cout << memo[i] << " " << memo[i+N] << endl;
K -= i;
res += memo[i].second;
ll buy = memo[i+N].second - memo[i].second;
res += K/N*buy;
K -= K/N*N;
res += memo[i+N+K].second - memo[i+N].second;
break;
}
return res;
}
/*
6 1000
001201
*/
int main(void) {
cin.tie(0); ios_base::sync_with_stdio(false);
cout << solve() << endl;
return 0;
}
kei