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 <bits/stdc++.h>
#define int long long
using namespace std;
string to_string(string s) { return s; }
template <typename T> string to_string(T v) {
bool first = true;
string res = "[";
for (const auto &x : v) {
if (!first)
res += ", ";
first = false;
res += to_string(x);
}
res += "]";
return res;
}
void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
cout << ' ' << to_string(H);
dbg_out(T...);
}
#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
struct Etat {
int nbElem;
int deb, fin;
};
signed main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
int curPos = 0;
auto Solve = [&](auto solve) -> Etat {
if (s[curPos++] == '?')
return Etat{1, 1, 1};
if (s[curPos++] == 'a') {
assert(s[curPos++] == 'x');
assert(s[curPos++] == '(');
Etat lft = solve(solve);
assert(s[curPos++] == ',');
Etat rgt = solve(solve);
assert(s[curPos++] == ')');
return Etat{lft.nbElem + rgt.nbElem, lft.deb + rgt.deb,
max(lft.nbElem + rgt.fin, lft.fin + rgt.nbElem)};
} else {
assert(s[curPos++] == 'n');
assert(s[curPos++] == '(');
Etat lft = solve(solve);
assert(s[curPos++] == ',');
Etat rgt = solve(solve);
assert(s[curPos++] == ')');
return Etat{lft.nbElem + rgt.nbElem, min(lft.deb, rgt.deb),
lft.fin + rgt.fin - 1};
}
};
Etat etat = Solve(Solve);
cout << etat.fin - etat.deb + 1 << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |