# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
148811 | 1 WA = 5 Push Up (#200) | HicCup (FXCUP4_hiccup) | C++17 | 57 ms | 8192 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;
int N;
std::string S;
int myS[1000010];
char myST[1000010], top;
int state[1000010];
bool able(int v)
{
top = 0;
for (int i = 0; i < N; i++)
{
myST[++top] = S[i];
if (S[i] == 'H')
state[top] = 1;
if (S[i] == 'C')
{
if (state[top - 1] == 1)
state[top] = 2;
else return false;
}
if (S[i] == '!')
{
if (state[top - 1] <= 1) top--;
if (state[top - 1] > 1)
state[top] = state[top - 1] + 1;
}
if (state[top] == v + 2)
top -= v + 2;
}
return state[top] == 0;
}
int HicCup(std::string S_) {
S = S_;
N = S.size();
stack <int> ST;
for (int i = 0; i < N; i++)
{
if (S[i] == 'H') ST.push(i);
if (S[i] == 'C')
{
if (ST.empty()) return -1;
myS[ST.top()] = i;
ST.pop();
}
}
if (!ST.empty()) return -1;
for (int i = 0; i < N; i++)
if (S[i] == '!')
{
if (i == 0) return -1;
if (S[i - 1] == 'H') return -1;
}
int s, e, v;
s = 0; e = (1 << 20) - 1;
while (s < e)
{
v = (s + e) / 2;
if (able(v + 1)) s = v + 1;
else e = v;
}
return s;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |