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"
using namespace std;
char ch[1010101];
int am[1010101], scn;
bool isok(int N, string &S, int K){
scn=0;
for(int i=0; i<N; i++){
if(S[i]=='H') ch[scn]='H', am[scn++]=0;
if(S[i]=='C'){
while(1){
if(!scn || ch[scn-1]=='C') return 0;
scn--;
if(ch[scn]=='H') break;
if(ch[scn]=='X' && am[scn]) return 0;
}
if(scn && ch[scn-1]=='X') am[scn-1]+=K;
else ch[scn]='X', am[scn++]=K;
}
if(S[i]=='!'){
if(!scn || ch[scn-1]!='X') return 0;
am[scn-1]--;
if(am[scn-1]<0) am[scn-1]=0;
}
}
while(scn){
scn--;
if(ch[scn]=='H' || ch[scn]=='C') return 0;
if(ch[scn]=='X' && am[scn]) return 0;
}
return 1;
}
int HicCup(string S) {
int N=S.size();
int mi=0, mx=N, md, dap=-1;
while(mi<=mx){
md=(mi+mx)/2;
if(isok(N, S, md)) dap=md, mi=md+1;
else mx=md-1;
}
return dap;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |