This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "hiccup.h"
#include<vector>
#include<deque>
using namespace std;
bool f(string& S, int X){
deque<int>Q(S.begin(),S.end());
vector<int>V{-1};
bool z=0;
while(!Q.empty()){
char q=Q.front();
Q.pop_front();
if(q=='H'){
z=0;
V.emplace_back(0);
}else if(q=='C'){
z=0;
if(V.back()!=0)return false;
V.back()=1;
if(X==0)V.pop_back();
}else{
if(V.back()<1){
if(!z)return false;
continue;
}
V.back()++;
if(V.back()==X+1){
V.pop_back();
z=1;
}
}
}
if(V.size()>1)return false;
return true;
}
int HicCup(std::string S) {
int N = S.size();
int l=-1,r=N;
while(l<r){
int X=(l+r+1)/2;
if(f(S,X))l=X;
else r=X-1;
}
return l;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |