#include "hiccup.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
#define MAX 9223372036854775807LL
#define MIN -9223372036854775807LL
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(10);
#define sp << " "
#define en << "\n"
#define compress(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end())
ll l, r;
ll Len;
string s;
int HicCup(std::string S)
{
s = S;
Len = (ll)s.size();
l = 0, r = Len;
for(ll i = 1 ; i < Len ; i++)
{
if(s[i] == '!' && s[i - 1] == 'H')
return -1;
}
while(l <= r)
{
ll mid = (l + r) >> 1;
stack<ll> stk;
ll ff = 0;
ll HC = 0;
for(ll i = 0 ; i < Len ; i++)
{
if(s[i] == 'H')
stk.push(1);
else if(s[i] == 'C')
{
while(!stk.empty() && stk.top() != 1)
{
if(stk.top() < 0)
ff = 1;
stk.pop();
}
if(ff)
break;
if(stk.empty())
{
ff = 1;
break;
}
stk.pop();
if(mid)
stk.push(-mid);
HC = 1;
}
else if(s[i] == '!')
{
if(stk.empty())
{
if(!HC)
{
ff = 1;
break;
}
continue;
}
if(stk.top() >= 0)
continue;
ll gap = stk.top() + 1;
stk.pop();
if(gap < 0)
stk.push(gap);
}
}
if(!stk.empty())
ff = 1;
if(ff)
r = mid - 1;
else
l = mid + 1;
}
return (int)r;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
12 ms |
5080 KB |
Output is correct |
6 |
Correct |
5 ms |
5104 KB |
Output is correct |
7 |
Correct |
5 ms |
5184 KB |
Output is correct |
8 |
Correct |
12 ms |
5204 KB |
Output is correct |
9 |
Correct |
12 ms |
5204 KB |
Output is correct |
10 |
Correct |
5 ms |
5204 KB |
Output is correct |
11 |
Correct |
0 ms |
312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
12 ms |
5080 KB |
Output is correct |
6 |
Correct |
5 ms |
5104 KB |
Output is correct |
7 |
Correct |
5 ms |
5184 KB |
Output is correct |
8 |
Correct |
12 ms |
5204 KB |
Output is correct |
9 |
Correct |
12 ms |
5204 KB |
Output is correct |
10 |
Correct |
5 ms |
5204 KB |
Output is correct |
11 |
Correct |
0 ms |
312 KB |
Output is correct |
12 |
Correct |
9 ms |
5196 KB |
Output is correct |
13 |
Correct |
6 ms |
5264 KB |
Output is correct |
14 |
Correct |
5 ms |
5204 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
5204 KB |
Output is correct |
17 |
Correct |
0 ms |
308 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
568 KB |
Output is correct |
20 |
Correct |
21 ms |
5204 KB |
Output is correct |
21 |
Correct |
14 ms |
5212 KB |
Output is correct |
22 |
Correct |
35 ms |
5132 KB |
Output is correct |
23 |
Correct |
36 ms |
4940 KB |
Output is correct |
24 |
Correct |
54 ms |
5204 KB |
Output is correct |
25 |
Correct |
11 ms |
5212 KB |
Output is correct |
26 |
Correct |
13 ms |
5204 KB |
Output is correct |
27 |
Correct |
13 ms |
5224 KB |
Output is correct |
28 |
Correct |
42 ms |
5200 KB |
Output is correct |
29 |
Correct |
54 ms |
4948 KB |
Output is correct |
30 |
Correct |
53 ms |
5204 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
5 ms |
652 KB |
Output is correct |