# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
150765 | 오리버스부릉부릉 (#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 <stack>
#include <vector>
using namespace std;
int HicCup(std::string S) {
bool flag = false;
int N = S.size();
int sp, wp;
stack<int> sta;
for (int i = 0; i < N; i++) {
if (S[i] == '!') {
if (!flag) return -1;
continue;
}
if (S[i] == 'H') {
sta.push(1);
}
else {
if (sta.empty()) return -1;
else {
sta.pop();
flag = true;
}
}
}
if (!sta.empty()) return -1;
int ret = 0;
int l = 1, r = 1000000, mid;
while (l <= r) {
bool suc = true;
mid = (l + r) / 2;
sp = wp = 0;
bool flag = false;
for (int i = 0; i < N; i++) {
if (S[i] == '!') {
if (!flag && (sta.empty() || sta.top() == -1)) {
suc = false;
break;
}
else if(!sta.empty() && sta.top() > 0){
sta.top()--;
if (sta.top() == 0) sta.pop();
}
}
else if (S[i] == 'H') {
sta.push(-1);
}
else {
if (sta.empty() || sta.top() != -1) {
suc = false;
break;
}
else {
sta.pop();
sta.push(mid);
flag = true;
}
}
}
if (suc) {
ret = mid;
l = mid + 1;
}
else r = mid - 1;
}
return ret;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |