#include "hiccup.h"
#include <bits/stdc++.h>
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const int N = 1e6+5;
int n, lvl[N];
bool checkFunction(string str, int mid) {
stack<pii> stk;
for(int i = 0; i < n; ++i) {
if(str[i] == 'C') stk.emplace(0, lvl[i]);
if(str[i] == '!') {
if(stk.empty()) continue;
if(stk.top().y != lvl[i]) continue;
pii v = stk.top(); stk.pop();
if(++v.x == mid) continue;
stk.emplace(v);
}
}
return stk.empty();
}
int HicCup(string S) {
n = S.size();
int cnt = 0, pv = -1;
for(int i = 0; i < n; ++i) {
if(S[i] == 'H') cnt++, pv = -1;
if(S[i] == 'C') {
lvl[i] = cnt;
if(!~--cnt) return -1;
else pv = i;
}
if(S[i] == '!') {
if(pv == -1) return -1;
else lvl[i] = lvl[pv];
}
}
if(cnt) return -1;
int l = 0, r = S.size();
while(l < r) {
int mid = (l + r + 1) >> 1;
if(checkFunction(S, mid)) l = mid;
else r = mid-1;
}
return l;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
11 ms |
712 KB |
Output is correct |
5 |
Correct |
208 ms |
12392 KB |
Output is correct |
6 |
Correct |
12 ms |
3328 KB |
Output is correct |
7 |
Correct |
13 ms |
3328 KB |
Output is correct |
8 |
Correct |
207 ms |
12392 KB |
Output is correct |
9 |
Correct |
209 ms |
12392 KB |
Output is correct |
10 |
Correct |
12 ms |
3328 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
11 ms |
712 KB |
Output is correct |
5 |
Correct |
208 ms |
12392 KB |
Output is correct |
6 |
Correct |
12 ms |
3328 KB |
Output is correct |
7 |
Correct |
13 ms |
3328 KB |
Output is correct |
8 |
Correct |
207 ms |
12392 KB |
Output is correct |
9 |
Correct |
209 ms |
12392 KB |
Output is correct |
10 |
Correct |
12 ms |
3328 KB |
Output is correct |
11 |
Correct |
15 ms |
3968 KB |
Output is correct |
12 |
Correct |
14 ms |
4736 KB |
Output is correct |
13 |
Correct |
14 ms |
3712 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
13 ms |
3328 KB |
Output is correct |
16 |
Correct |
6 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
6 ms |
640 KB |
Output is correct |
19 |
Correct |
85 ms |
8108 KB |
Output is correct |
20 |
Incorrect |
91 ms |
8364 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |