#include "hiccup.h"
int HicCup(std::string s) {
int n = (int)s.size(), c = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'H') c++;
if (s[i] == 'C') c--;
if (c < 0) return -1;
}
if (c) return -1;
int l = 0, r = 890328;
while (l + 1 < r) {
int m = (l + r) >> 1, c = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'C') c -= m;
if (c < -20000328) break;
if (s[i] == '!') c++;
if (c > 0) c = 0;
}
if (c) r = m;
else l = m;
}
return l;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 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 |
9 ms |
512 KB |
Output is correct |
5 |
Correct |
60 ms |
3328 KB |
Output is correct |
6 |
Correct |
13 ms |
3328 KB |
Output is correct |
7 |
Correct |
14 ms |
3328 KB |
Output is correct |
8 |
Correct |
59 ms |
3328 KB |
Output is correct |
9 |
Correct |
62 ms |
3328 KB |
Output is correct |
10 |
Correct |
13 ms |
3328 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 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 |
9 ms |
512 KB |
Output is correct |
5 |
Correct |
60 ms |
3328 KB |
Output is correct |
6 |
Correct |
13 ms |
3328 KB |
Output is correct |
7 |
Correct |
14 ms |
3328 KB |
Output is correct |
8 |
Correct |
59 ms |
3328 KB |
Output is correct |
9 |
Correct |
62 ms |
3328 KB |
Output is correct |
10 |
Correct |
13 ms |
3328 KB |
Output is correct |
11 |
Correct |
15 ms |
3328 KB |
Output is correct |
12 |
Correct |
14 ms |
3328 KB |
Output is correct |
13 |
Correct |
13 ms |
3328 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Incorrect |
38 ms |
3328 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |