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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
char str[1000002];
bool able(int x){
vector<int> stk;
bool last = 0; /// 마지막이 느낌표
for(int i=1; i<=n; i++){
if(str[i] == 'H') stk.push_back(-1), last = 0;
else if(str[i] == 'C'){
if(stk.empty() || stk.back() != -1) return false;
stk.back()++;
if(x==0){
last = 1;
stk.pop_back();
}
else last = 0;
}
else{
if(stk.empty() || stk.back() == -1){
if(last) {}
else return false;
}
else{
stk.back()++;
if(stk.back() >= x) stk.pop_back(), last = 1;
else last = 0;
}
}
}
return stk.empty();
}
int HicCup(string S){
n = S.size();
for(int i=1; i<=n; i++) str[i] = S[i-1];
int L = 0, R = n, ANS = -1;
while(L<=R){
int M = (L+R)/2;
if(able(M)) ANS = M, L = M+1;
else R = M-1;
}
return ANS;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |