# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
148644 | お前はもう死んでいる (#200) | HicCup (FXCUP4_hiccup) | C++17 | 39 ms | 5492 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>
#include <cassert>
#include <iostream>
int pos = 0;
char lookup(const std::string &S) {
if(pos >= S.size()) {
return '#';
} else if(S[pos] == '!') {
return '.';
} else if(S[pos] == 'H') {
return '(';
} else {
return ')';
}
}
int solve(const std::string &S, bool good = false) {
int ans = 0;
int rest = 1e8;
if(lookup(S) != '(') {
return -1;
}
std::vector<int> wtf;
while(1) {
//std::cout << "lookup is " << lookup(S) << '\n';
if(lookup(S) == '#') {
return good ? std::min(ans, rest) : -1;
} else if(lookup(S) == '(') {
pos++;
if(lookup(S) == '#' || lookup(S) == '.') {
return -1;
} else if(lookup(S) == '(') {
rest = std::min(rest, solve(S));
if(rest == -1) return -1;
assert(lookup(S) == ')');
pos++;
if(wtf.empty()) {
wtf.push_back(0);
}
ans = 0;
wtf[0]++;
} else if(lookup(S) == ')') {
pos++;
if(wtf.empty()) {
wtf.push_back(0);
}
ans = 0;
wtf[0]++;
}
} else if(lookup(S) == ')') {
return std::min(ans, rest);
} else if(lookup(S) == '.') {
pos++;
if(wtf.empty()) {
return -1;
}
wtf[ans]--;
if(ans + 1 >= wtf.size()) {
wtf.push_back(0);
}
wtf[ans+1]++;
if(wtf[ans] == 0) {
ans++;
}
}
}
}
int HicCup(std::string S) {
int n = S.size();
int ans = solve(S, true);
if(pos != n) {
ans = -1;
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |