# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
150052 | GucciBelt (#200) | HicCup (FXCUP4_hiccup) | C++17 | 217 ms | 5444 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;
const int N = 1e6+5;
int HicCup(string S) {
stack<int> stk;
for(int i = 0; i < S.size(); i++) {
if(S[i] == 'H') stk.emplace(i);
else if(S[i] == 'C') {
if(stk.empty()) return -1;
else stk.pop();
}
}
if(!stk.empty()) return -1;
int l = 0, r = S.size();
while(l < r) {
int mid = (l + r + 1) >> 1;
queue<int> Q;
bool chk = false;
for(int i = 0; i < S.size(); i++) {
if(S[i] == 'C') {
chk = true;
Q.emplace(0);
} else if(S[i] == '!') {
if(Q.empty() && !chk) return -1;
else if(!Q.empty()) {
int now = Q.front(); Q.pop();
if(now + 1 < mid) Q.emplace(now + 1);
}
}
}
if(Q.empty()) l = mid;
else r = mid - 1;
}
return l;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |