#include "hiccup.h"
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if(test)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 1;
int cnt, N;
string str;
vector<int> v;
bool chk(int x){
bool chk = false;
while(!v.empty()) v.pop_back();
cnt = 0;
for(int i=0; i<N; i++){
if(str[i]=='H'){
cnt++;
}else if(str[i]=='C'){
if(cnt==0){
return false;
}
cnt--;
if(x!=0) v.pb(x);
chk = true;
}else{
if(!v.empty()){
int k = v.back(); v.pop_back();
k--;
if(k>0){
v.pb(k);
}
}else{
if(!chk) return false;
}
}
}
if(v.empty()) return true;
return false;
}
int HicCup(string S) {
str = S;
N = S.size();
int s = 0, e = S.size()-1, m;
while(s<e){
m = (s+e)/2+1;
if(chk(m)){
s = m;
}else{
e = m-1;
}
}
if(chk(s)){
return s;
}else{
return -1;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
11 ms |
768 KB |
Output is correct |
5 |
Correct |
186 ms |
6516 KB |
Output is correct |
6 |
Correct |
13 ms |
4352 KB |
Output is correct |
7 |
Correct |
14 ms |
4352 KB |
Output is correct |
8 |
Correct |
186 ms |
6516 KB |
Output is correct |
9 |
Correct |
184 ms |
6516 KB |
Output is correct |
10 |
Correct |
14 ms |
4352 KB |
Output is correct |
11 |
Incorrect |
6 ms |
384 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
11 ms |
768 KB |
Output is correct |
5 |
Correct |
186 ms |
6516 KB |
Output is correct |
6 |
Correct |
13 ms |
4352 KB |
Output is correct |
7 |
Correct |
14 ms |
4352 KB |
Output is correct |
8 |
Correct |
186 ms |
6516 KB |
Output is correct |
9 |
Correct |
184 ms |
6516 KB |
Output is correct |
10 |
Correct |
14 ms |
4352 KB |
Output is correct |
11 |
Correct |
49 ms |
4988 KB |
Output is correct |
12 |
Correct |
51 ms |
4736 KB |
Output is correct |
13 |
Correct |
20 ms |
4352 KB |
Output is correct |
14 |
Correct |
6 ms |
384 KB |
Output is correct |
15 |
Incorrect |
94 ms |
4480 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |