# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
613034 | 2022-07-30T03:02:52 Z | czhang2718 | HicCup (FXCUP4_hiccup) | C++17 | 0 ms | 0 KB |
#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; }