이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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),r=false;
else if(i=='C'){
if(!st.empty()) 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;
//printf("%d %d %d\n",l,r,mid);
stack<pair<int,int>> s;
for(auto i:S){
//if(!s.empty()) printf("%d %d\n",s.top().first,s.top().second);
//else printf("��\n");
if(i=='H') s.push({1,0});
else if(!s.empty()&&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;
}
}
컴파일 시 표준 에러 (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... |