#include "hiccup.h"
#include <algorithm>
#include <vector>
#include <tuple>
using namespace std;
typedef pair<int, int> pii;
int n;
char S[1000001];
int nxt[1000002];
int prv[1000002];
vector<pii> P;
bool check(int x) {
for (int i = 1; i <= n; ++i) {
nxt[i] = i + 1;
prv[i] = i - 1;
}
for (pii _i : P) {
int a, b;
tie(a, b) = _i;
int cnt = 0, i;
for (i = nxt[b]; cnt < x && i <= n && S[i] == '!'; i = nxt[i], ++cnt);
if (cnt < x) return 0;
if (nxt[a] == b) {
nxt[prv[a]] = i;
prv[i] = prv[a];
}
else {
nxt[prv[a]] = nxt[a];
prv[nxt[a]] = prv[a];
nxt[prv[b]] = i;
prv[i] = prv[b];
}
}
return 1;
}
int HicCup(string _S) {
n = _S.length();
vector<int> st;
S[0] = 'H';
for (int i = 0; i < n; ++i) {
S[i + 1] = _S[i];
if (S[i + 1] == 'H') st.push_back(i + 1);
else if (S[i + 1] == 'C') {
if (st.empty()) return -1;
P.emplace_back(st.back(), i + 1);
st.pop_back();
}
if (S[i] == 'H' && S[i + 1] == '!') return -1;
}
if (!st.empty()) return -1;
if (P.empty()) return -1;
int s = 0, e = n;
sort(P.begin(), P.end(), [&](pii a, pii b) {
return a.second > b.second;
});
while (s < e) {
int m = (s + e + 1) / 2;
if (check(m)) s = m;
else e = m - 1;
}
return s;
}
# |
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 |
512 KB |
Output is correct |
4 |
Correct |
7 ms |
1148 KB |
Output is correct |
5 |
Correct |
66 ms |
16100 KB |
Output is correct |
6 |
Correct |
12 ms |
3328 KB |
Output is correct |
7 |
Correct |
13 ms |
3328 KB |
Output is correct |
8 |
Correct |
59 ms |
16104 KB |
Output is correct |
9 |
Correct |
61 ms |
16096 KB |
Output is correct |
10 |
Correct |
13 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 |
512 KB |
Output is correct |
4 |
Correct |
7 ms |
1148 KB |
Output is correct |
5 |
Correct |
66 ms |
16100 KB |
Output is correct |
6 |
Correct |
12 ms |
3328 KB |
Output is correct |
7 |
Correct |
13 ms |
3328 KB |
Output is correct |
8 |
Correct |
59 ms |
16104 KB |
Output is correct |
9 |
Correct |
61 ms |
16096 KB |
Output is correct |
10 |
Correct |
13 ms |
3328 KB |
Output is correct |
11 |
Correct |
15 ms |
4728 KB |
Output is correct |
12 |
Correct |
16 ms |
4348 KB |
Output is correct |
13 |
Correct |
13 ms |
3456 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
13 ms |
3328 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
640 KB |
Output is correct |
19 |
Correct |
52 ms |
12160 KB |
Output is correct |
20 |
Incorrect |
43 ms |
12288 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |