# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
150493 | Little Piplup (#200) | HicCup (FXCUP4_hiccup) | C++17 | 828 ms | 20568 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "hiccup.h"
#include<bits/stdc++.h>
using std::vector;
using std::cout;
using std::string;
using std::endl;
using std::stack;
int ans(string S) {
int N = S.size();
if ( S[0] != 'H' ) return -1;
vector<int> parse;
int temp = 0;
for ( int i = 0 ; i < N ; ++i ) {
if ( S[i] == 'H' ) {
if ( temp ) {
parse.push_back(temp);
temp = 0;
}
parse.push_back(-2);
} else if ( S[i] == 'C' ) {
if ( temp ) {
parse.push_back(temp);
temp = 0;
}
parse.push_back(-1);
} else {
++temp;
}
}
if ( temp ) {
parse.push_back(temp);
}
int size = parse.size();
int up = N+3, down = 0;
while( down + 1 < up ) {
int cur = (up + down)/2;
//std::cout<<up<<" "<<down<<std::endl;
stack<int> boo;
for ( int i = 0 ; i < size ; ++i ) {
//push current
boo.push(parse[i]);
//pop if possible
while( boo.size() > 2 ){
int c = boo.top();
boo.pop();
int b = boo.top();
boo.pop();
int a = boo.top();
boo.pop();
if ( a == -2 && b == -1 && c >= cur ) {
if ( boo.empty() || boo.top() == -2 || c == cur) {
//do nothing
} else { //push back
c -= cur;
if ( boo.top() == -1 ) {
boo.push(c);
} else {
int temp = boo.top();
boo.pop();
boo.push(temp+c);
}
}
} else {
boo.push(a);
boo.push(b);
boo.push(c);
break;
}
}
}
if ( boo.empty() ) {
down = cur;
} else {
up = cur;
}
}
return down;
}
int HicCup(string s)
{
if(ans(s)==0)
{
string newstr;
for(int i=0; i<s.size(); i++)
{
newstr.push_back(s[i]);
if(s[i]=='C')
{
newstr.push_back('!');
}
}
if(ans(newstr)==1)
return 0;
else
return -1;
}
else
return ans(s);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |