#include<vector>
#include<algorithm>
#include "hiccup.h"
int HicCup(std::string S) {
int N = S.size();
int stack = 0;
int mark = 0;
std::vector<int> v;
for(auto i:S){
if(i == '!') mark++;
}
int left=0, right=mark;
for(int i=0; i<N; i++){
if(S[i] == 'H') stack++;
if(S[i] == 'C'){
stack--;
if(stack < 0) return -1;
v.push_back(mark);
}
if(S[i] == '!') mark--;
}
while(left < right){
int mid = (left+right)/2;
int prev = v[0];
for(auto i:v){
prev = std::min(prev, i) - mid;
}
if(prev < 0) right = mid-1;
left = mid+1;
}
int ans = 0;
for(int mid=left-3; mid <= left+3; mid++){
int prev = v[0];
for(auto i:v){
prev = std::min(prev, i) - mid;
}
if(prev < 0) break;
ans = mid;
}
if(stack) return -1;
return ans;
}
# |
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 |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
640 KB |
Output is correct |
5 |
Correct |
28 ms |
5492 KB |
Output is correct |
6 |
Correct |
15 ms |
3328 KB |
Output is correct |
7 |
Correct |
15 ms |
3072 KB |
Output is correct |
8 |
Correct |
30 ms |
5484 KB |
Output is correct |
9 |
Correct |
29 ms |
5492 KB |
Output is correct |
10 |
Correct |
15 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 |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
640 KB |
Output is correct |
5 |
Correct |
28 ms |
5492 KB |
Output is correct |
6 |
Correct |
15 ms |
3328 KB |
Output is correct |
7 |
Correct |
15 ms |
3072 KB |
Output is correct |
8 |
Correct |
30 ms |
5484 KB |
Output is correct |
9 |
Correct |
29 ms |
5492 KB |
Output is correct |
10 |
Correct |
15 ms |
3328 KB |
Output is correct |
11 |
Correct |
19 ms |
3712 KB |
Output is correct |
12 |
Correct |
17 ms |
3712 KB |
Output is correct |
13 |
Correct |
14 ms |
3328 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Incorrect |
17 ms |
3328 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |