# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
149897 | | 팀명못정해서15시간째고민중인팀 (#200) | HicCup (FXCUP4_hiccup) | C++17 | | 303 ms | 7416 KiB |
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;
int HicCup(std::string S) {
int n=S.size();
bool chk=true,av=false;
int t=0;
for(auto i:S){
if(i=='H') t++,av=false;
if(i=='C'){
if(t) t--,av=true;
else chk=false;
}
if(i=='!'&&!av) chk=false;
}
if(t||!chk) return -1;
int l=0,r=1000000,Max=0;
while(l<=r){
int mid=(l+r)/2;
bool ichk=true;
//printf("%d %d %d\n",l,r,mid);
stack<pair<int,int>> st;
for(auto i:S){
//printf("%c\n",i);
//if(!st.empty()) printf("%d %d\n",st.top().first,st.top().second);
if(i=='H') st.push({1,0});
if(i=='C'){
if(!st.empty()){
if(st.top().first==1) st.pop(),st.push({2,0});
else if(st.top().second<mid) {ichk=false;break;}
}
}
if(i=='!'&&!st.empty()){
if(!st.empty()&&st.top().first==2){
int c=st.top().second; st.pop();
st.push({2,c+1});
}
while(!st.empty()&&st.top().first==2&&st.top().second==mid) st.pop();
}
}
while(!st.empty()&&st.top().second==mid) st.pop();
if(st.empty()&&ichk) Max=max(Max,mid),l=mid+1;
else r=mid-1;
//printf("\n");
}
return Max;
}
Compilation message (stderr)
hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:6:6: warning: unused variable 'n' [-Wunused-variable]
int n=S.size();
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |