#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--;
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 |
432 KB |
Output is correct |
2 |
Incorrect |
6 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
432 KB |
Output is correct |
2 |
Incorrect |
6 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |