#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;
ll cnt, N;
string str;
vector<pii> v;
bool chk(ll x){
bool chk = false;
while(!v.empty()){
v.pop_back();
}
for(int i=0; i<N; i++){
if(str[i]=='H'){
v.pb({1, 0});
}else if(str[i]=='C'){
while(1){
if(v.empty()) return false;
pii now = v.back(); v.pop_back();
if(now.first==1){
v.pb({2, 0});
break;
}else if(now.first==2){
if(now.second<x){
return false;
}
}
}
}else{
while(1){
if(v.empty()) return false;
pii now = v.back(); v.pop_back();
if(now.first==1){
return false;
}
if(!v.empty() && v.back().first==2 && now.second>=x){
continue;
}
now.second++;
v.pb(now);
break;
}
}
}
while(!v.empty()){
pii now = v.back(); v.pop_back();
if(now.first==1 || now.second<x) return false;
}
return v.empty();
}
int HicCup(string S) {
str = S;
N = S.size();
/*for(int i=0; i<N; i++){
if(S[i]=='H'){
cnt++;
}else if(S[i]=='C'){
if(cnt==0){
return -1;
}
cnt--;
}
}
if(cnt!=0){
return -1;
}*/
int s = 0, e = S.size()-1, m;
while(s<e){
m = (s+e)/2+1;
if(chk((ll)m)){
s = m;
}else{
e = m-1;
}
}
if(!chk(s)){
return -1;
}
return s;
}
Compilation message
hiccup.cpp: In function 'bool chk(ll)':
hiccup.cpp:36:7: warning: unused variable 'chk' [-Wunused-variable]
bool chk = false;
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
7 ms |
512 KB |
Output is correct |
5 |
Correct |
29 ms |
4352 KB |
Output is correct |
6 |
Correct |
15 ms |
4224 KB |
Output is correct |
7 |
Correct |
14 ms |
4352 KB |
Output is correct |
8 |
Correct |
30 ms |
4224 KB |
Output is correct |
9 |
Correct |
28 ms |
4352 KB |
Output is correct |
10 |
Correct |
13 ms |
4224 KB |
Output is correct |
11 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
7 ms |
512 KB |
Output is correct |
5 |
Correct |
29 ms |
4352 KB |
Output is correct |
6 |
Correct |
15 ms |
4224 KB |
Output is correct |
7 |
Correct |
14 ms |
4352 KB |
Output is correct |
8 |
Correct |
30 ms |
4224 KB |
Output is correct |
9 |
Correct |
28 ms |
4352 KB |
Output is correct |
10 |
Correct |
13 ms |
4224 KB |
Output is correct |
11 |
Correct |
17 ms |
4352 KB |
Output is correct |
12 |
Correct |
23 ms |
4352 KB |
Output is correct |
13 |
Correct |
20 ms |
4224 KB |
Output is correct |
14 |
Correct |
6 ms |
256 KB |
Output is correct |
15 |
Correct |
15 ms |
4224 KB |
Output is correct |
16 |
Correct |
5 ms |
512 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
7 ms |
640 KB |
Output is correct |
19 |
Correct |
44 ms |
4352 KB |
Output is correct |
20 |
Correct |
29 ms |
4352 KB |
Output is correct |
21 |
Correct |
79 ms |
4096 KB |
Output is correct |
22 |
Correct |
66 ms |
4096 KB |
Output is correct |
23 |
Correct |
92 ms |
4352 KB |
Output is correct |
24 |
Correct |
29 ms |
4352 KB |
Output is correct |
25 |
Correct |
27 ms |
4352 KB |
Output is correct |
26 |
Correct |
33 ms |
4352 KB |
Output is correct |
27 |
Correct |
80 ms |
4352 KB |
Output is correct |
28 |
Correct |
100 ms |
4224 KB |
Output is correct |
29 |
Correct |
93 ms |
4352 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
11 ms |
640 KB |
Output is correct |
33 |
Correct |
6 ms |
384 KB |
Output is correct |