# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
149320 | 20190901 (#200) | HicCup (FXCUP4_hiccup) | C++17 | 441 ms | 20416 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 <vector>
using namespace std;
bool Check(string str, int mid)
{
vector<pair<char, int>> stk;
int hCnt = 0;
int cCnt = 0;
bool isMake = false;
for (int i = 0; i < str.size(); i++)
{
if (stk.empty() && str[i] != '!')
isMake = false;
if (str[i] == 'H')
{
stk.push_back({ 'H', -1 });
hCnt++;
}
else if (str[i] == 'C')
{
if (hCnt > cCnt)
stk.push_back({ 'C', 0 });
else
return false;
cCnt++;
}
else
{
if (stk.empty())
{
if (isMake)
continue;
else
return false;
}
if (stk.back().first == 'H')
{
if (isMake)
continue;
else
return false;
}
stk.push_back({ '!', stk.back().second + 1 });
}
if (stk.back().second == mid)
{
for (int i = 0; i < mid + 2; i++)
{
if (stk.empty())
return false;
if (stk.back().first == 'C')
cCnt--;
else if (stk.back().first == 'H')
hCnt--;
stk.pop_back();
}
isMake = true;
}
}
for (int i = 0; i < stk.size(); i++)
{
if (stk[i].first != '!')
return false;
}
return true;
}
int HicCup(string S)
{
int lo = -1;
int hi = (int)S.size();
while (lo + 1 < hi)
{
int mid = (lo + hi) >> 1;
if (Check(S, mid))
{
lo = mid;
}
else
{
hi = mid;
}
}
return lo;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |