# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
150429 | Little Piplup (#200) | HicCup (FXCUP4_hiccup) | C++17 | 256 ms | 6320 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;
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;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |