#include "hiccup.h"
#include <bits/stdc++.h>
using namespace std;
string s;
bool possible(int k) {
vector<int> v;
if (s[0] == '!') return false;
int waste = 0;
for (char i : s) {
if (i == 'H') v.push_back(0);
if (!v.empty() and ((v.back() == 0 and i == 'H') or (v.back() == 1 and i == 'C') or (v.back() >= 2 and i == '!'))) v.back()++;
else if (not (waste and i == '!')) return false;
if (!v.empty() and v.back() == k+2) v.pop_back(), waste = 1;
else if (i != '!') waste = 0;
}
return v.empty();
}
int HicCup(string S) {
s = S;
int l = -1, r = 1000004;
while (l+1<r) {
int m = (l+r)/2;
if (possible(m)) l = m;
else r = m;
}
return l;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 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 |
7 ms |
512 KB |
Output is correct |
5 |
Correct |
23 ms |
4312 KB |
Output is correct |
6 |
Correct |
15 ms |
4352 KB |
Output is correct |
7 |
Correct |
14 ms |
4352 KB |
Output is correct |
8 |
Correct |
22 ms |
4224 KB |
Output is correct |
9 |
Correct |
25 ms |
4352 KB |
Output is correct |
10 |
Correct |
14 ms |
4352 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 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 |
7 ms |
512 KB |
Output is correct |
5 |
Correct |
23 ms |
4312 KB |
Output is correct |
6 |
Correct |
15 ms |
4352 KB |
Output is correct |
7 |
Correct |
14 ms |
4352 KB |
Output is correct |
8 |
Correct |
22 ms |
4224 KB |
Output is correct |
9 |
Correct |
25 ms |
4352 KB |
Output is correct |
10 |
Correct |
14 ms |
4352 KB |
Output is correct |
11 |
Correct |
16 ms |
4224 KB |
Output is correct |
12 |
Correct |
16 ms |
4352 KB |
Output is correct |
13 |
Correct |
18 ms |
4352 KB |
Output is correct |
14 |
Correct |
6 ms |
384 KB |
Output is correct |
15 |
Correct |
15 ms |
4352 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
256 KB |
Output is correct |
18 |
Correct |
7 ms |
640 KB |
Output is correct |
19 |
Correct |
33 ms |
4352 KB |
Output is correct |
20 |
Correct |
20 ms |
4096 KB |
Output is correct |
21 |
Correct |
48 ms |
4352 KB |
Output is correct |
22 |
Correct |
49 ms |
3968 KB |
Output is correct |
23 |
Correct |
78 ms |
4352 KB |
Output is correct |
24 |
Correct |
20 ms |
4352 KB |
Output is correct |
25 |
Correct |
22 ms |
4352 KB |
Output is correct |
26 |
Correct |
22 ms |
4224 KB |
Output is correct |
27 |
Correct |
60 ms |
4352 KB |
Output is correct |
28 |
Correct |
76 ms |
4224 KB |
Output is correct |
29 |
Correct |
76 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 |
10 ms |
640 KB |
Output is correct |
33 |
Correct |
5 ms |
384 KB |
Output is correct |