# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
149344 | | 팀명못정해서15시간째고민중인팀 (#200) | HicCup (FXCUP4_hiccup) | C++17 | | 323 ms | 7492 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();
stack<int> st;
bool chk=true,r=false;
for(auto i:S){
if(i=='H') st.push(1);
else if(i=='C'){
if(!st.empty()&&st.top()) st.pop(),r=true;
else chk=false;
}
else if(!r) chk=false;
}
if(!st.empty()) chk=false;
if(!chk) return -1;
else{
int l=0,r=1000000,Max=0;
while(l<=r){
int mid=(l+r)/2;
stack<pair<int,int>> s;
for(auto i:S){
if(i=='H') s.push({1,0});
else if(i=='C') s.pop(),s.push({2,0});
else{
if(!s.empty()&&s.top().second==mid) s.pop();
if(!s.empty()){
int c=s.top().second; s.pop();
s.push({2,c+1});
}
if(!s.empty()&&s.top().second==mid) s.pop();
}
}
while(!s.empty()&&s.top().second==mid) s.pop();
if(s.empty()) l=mid+1,Max=max(Max,mid);
else r=mid-1;
}
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... |