# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
613034 | czhang2718 | HicCup (FXCUP4_hiccup) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}