Submission #613038

#TimeUsernameProblemLanguageResultExecution timeMemory
613038czhang2718HicCup (FXCUP4_hiccup)C++17
0 / 100
1 ms212 KiB
#include "hiccup.h" using namespace std; #include "bits/stdc++.h" int HicCup(std::string S) { int n = S.size(); auto check=[&](int x){ stack<char> s; int cur=0; for(int i=0; i<n; i++){ if(S[i]=='!'){ cur++; if(cur==x){ if(s.size()<2) return 0; char c=s.top(); s.pop(); char h=s.top(); s.pop(); if(c!='C' && h!='H') return 0; } cur=0; } if(S[i]=='C'){ if(cur) return 0; s.push('C'); } if(S[i]=='H'){ if(cur) return 0; s.push('H'); } } while(!s.empty()){ char c=s.top(); s.pop(); if(c!='!') return 0; } return 1; }; int x=0; for(int i=19; i>=0; i--){ if(x+(1<<i)<n && check(x+(1<<i))) x+=(1<<i); } if(!check(x)) return -1; return x; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...