# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
150864 | Welcome to osu! (#200) | HicCup (FXCUP4_hiccup) | C++17 | 6 ms | 384 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>
#define va first
#define vb second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int HicCup(std::string S) {
int N = S.size();
int lo=0, hi=N;
stack<pii> st;
while (lo<hi) {
while (!st.empty()) st.pop();
int mid = lo+hi+1>>1;
bool flag = true;
for (int i=0; i<N; i++) {
if (S[i] == 'H') st.push(pii('H', 0));
else if (S[i] == 'C') {
if (st.top().va != 'H') {
flag = false;
break;
}
st.pop();
st.push(pii('C', 1));
}
else if (S[i] == '!') {
if (st.top().va != 'C') {
flag = false;
break;
}
pii tmp = st.top();
st.pop();
st.push(pii('C', tmp.vb+1));
if (tmp.vb+1 == mid) st.pop();
}
}
if (!st.empty()) flag = false;
if (flag) lo = mid;
else hi = mid-1;
}
return lo;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |