結果
| 問題 |
No.78 クジ付きアイスバー
|
| コンテスト | |
| ユーザー |
nmnmnmnmnmnmnm
|
| 提出日時 | 2014-11-15 21:57:41 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,030 bytes |
| コンパイル時間 | 871 ms |
| コンパイル使用メモリ | 87,880 KB |
| 実行使用メモリ | 10,016 KB |
| 最終ジャッジ日時 | 2024-10-06 16:18:06 |
| 合計ジャッジ時間 | 10,478 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 2 TLE * 1 -- * 32 |
ソースコード
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define MOD 1000000009
int f1(int n, int k, string s){
int ans = 0;
long long atari = 0;
int index = 0;
for(;;){
if(s[index]=='0'){
if(atari==0){
ans++;
}
else{
atari--;
}
}
if(s[index]=='1'){
if(atari==0){
ans++;
atari++;
}
}
if(s[index]=='2'){
if(atari==0){
ans++;
atari+=2;
}
else{
atari++;
}
}
k--;
if(k==0)break;
index++;
index%=n;
}
return ans;
}
int f2(int n, int k, string s){
int ans = 0;
int atari = 0;
for(int i = 0; i < n; i++){
if(s[i]=='0'){
if(atari==0){
ans++;
}
else{
atari--;
}
}
if(s[i]=='1'){
if(atari==0){
ans++;
atari++;
}
}
if(s[i]=='2'){
if(atari==0){
ans++;
atari+=2;
}
else{
atari++;
}
}
}
int d = max(0,ans-atari);
int c = max(0,k/n-10);
return f1(n,k-c*n,s)+c*d;
}
int main(){
int n, k;
cin >> n >> k;
string s;
cin >> s;
if(n!=s.sz||k>2000000000||n>50){
cout << -1 <<endl;
return 0;
}
cout << f1(n,k,s) << endl;
//cout << f2(n,k,s) << endl;
return 0;
}
// シュミレーションがタイムアウトするかテスト
nmnmnmnmnmnmnm