# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
150429 | Little Piplup (#200) | HicCup (FXCUP4_hiccup) | C++17 | 256 ms | 6320 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "hiccup.h"
#include<bits/stdc++.h>
//using namespace std;
std::string str;
std::string ss;
bool check(int x)
{
int excount = 0;
ss.clear();
if (x+2 > str.size())
return false;
int ssize = 0;
int ccount = 0;
for (auto it:str)
{
if (it=='!')
excount++;
else
{
ss.push_back(it);
if (it=='C')
ccount++;
ssize++;
}
if (ssize < 2)
{
//std::cout << ss << std::endl;
continue;
}
bool ok = true;
ok &= ss[ssize-2] == 'C';
ok &= ss[ssize-1] == 'H';
ok &= (excount >= x);
if (ok)
{
ss.pop_back();
ss.pop_back();
ssize-=2;
ccount--;
excount -= x;
}
//std::cout << ss << std::endl;
}
for (auto it:ss)
{
if (it!='!')
return false;
}
return true;
}
bool zerocheck()
{
std::string tmpstr = "";
for (auto it:str)
{
tmpstr.push_back(it);
int sz = tmpstr.size();
if (sz>=2)
{
while (tmpstr[sz-1] == 'H' && tmpstr[sz-2] == 'C')
{
tmpstr.pop_back();
tmpstr.pop_back();
sz-=2;
while(tmpstr.back()=='!')
{
tmpstr.pop_back();
sz--;
}
}
}
else continue;
}
//std::cout << "zerocheck : " << tmpstr << std::endl;
return tmpstr.empty();
}
int HicCup(std::string S) {
int N = S.size();
if ( S[0] != 'H' ) return -1;
str = S;
std::reverse(str.begin(), str.end());
//std::cout << str << std::endl;
int lo = 0, hi = 1000000;
if (!zerocheck())
return -1;
while(lo + 1 < hi)
{
int mid = lo+hi;
mid /= 2;
//printf("Checking %d\n",mid);
if (check(mid))
{
//printf("OK %d\n",mid);
lo = mid;
}
else
{
//printf("NO %d\n",mid);
hi = mid;
}
}
return lo;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |