#include "hiccup.h"
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
using namespace std;
int HicCup(std::string S) {
int N = S.size();
int mask = 0;
int bal = 0;
for(int i=0; i<N; i++){
if(S[i] == '!' && mask != 3) return -1;
if(S[i] == 'H') bal++, mask |= 1;
if(S[i] == 'C') bal--, mask |= 2;
if(bal < 0) return -1;
}
if(bal > 0) return -1;
int cur[N], curcur[N], maskk[N];
int l=1, r=N, res=0;
while(l<=r){
int mid=(l+r)/2;
int ok = 1;
int level = 0;
cur[level] = 0;
curcur[level] = 0;
maskk[level] = 0;
for(int i=0; i<N; i++){
if(S[i] == 'H'){
maskk[level] |= 1;
level++;
cur[level] = 0;
curcur[level] = 0;
} else if(S[i] == 'C'){
if(cur[level] != 0){
ok = 0;
break;
}
level--;
cur[level]++;
maskk[level] |= 2;
} else{
if(level == -1) return -1;
if(maskk[level] != 3) return -1;
if(cur[level]){
curcur[level]++;
if(curcur[level] == mid){
cur[level]--;
curcur[level] = 0;
}
}
}
}
if(cur[0] == 0 && ok) res = mid, l = mid+1;
else r = mid-1;
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
6 ms |
512 KB |
Output is correct |
5 |
Correct |
25 ms |
3328 KB |
Output is correct |
6 |
Correct |
13 ms |
3328 KB |
Output is correct |
7 |
Correct |
13 ms |
3328 KB |
Output is correct |
8 |
Correct |
19 ms |
3328 KB |
Output is correct |
9 |
Correct |
19 ms |
3328 KB |
Output is correct |
10 |
Correct |
13 ms |
3328 KB |
Output is correct |
11 |
Correct |
6 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 |
6 ms |
512 KB |
Output is correct |
5 |
Correct |
25 ms |
3328 KB |
Output is correct |
6 |
Correct |
13 ms |
3328 KB |
Output is correct |
7 |
Correct |
13 ms |
3328 KB |
Output is correct |
8 |
Correct |
19 ms |
3328 KB |
Output is correct |
9 |
Correct |
19 ms |
3328 KB |
Output is correct |
10 |
Correct |
13 ms |
3328 KB |
Output is correct |
11 |
Correct |
21 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 |
Correct |
14 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 |
6 ms |
560 KB |
Output is correct |
19 |
Correct |
33 ms |
3328 KB |
Output is correct |
20 |
Correct |
27 ms |
3328 KB |
Output is correct |
21 |
Correct |
55 ms |
3328 KB |
Output is correct |
22 |
Correct |
55 ms |
3200 KB |
Output is correct |
23 |
Correct |
81 ms |
3328 KB |
Output is correct |
24 |
Correct |
18 ms |
3352 KB |
Output is correct |
25 |
Correct |
20 ms |
3328 KB |
Output is correct |
26 |
Correct |
19 ms |
3328 KB |
Output is correct |
27 |
Correct |
59 ms |
3328 KB |
Output is correct |
28 |
Correct |
78 ms |
3200 KB |
Output is correct |
29 |
Correct |
80 ms |
3328 KB |
Output is correct |
30 |
Correct |
6 ms |
384 KB |
Output is correct |
31 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |