This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;
#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout (T t, U...u) {cout << t << (sizeof... (u) ? ", " : ""), dout (u...);}
#else
#define debug(...) 7122
#endif
#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second
string s;
int p;
tuple<int, int, int> work() {
while (s[p] == ')' || s[p] == ',' || s[p] == '(') p++;
if (s[p] == '?') {
p++;
return {1, 1, 1};
}
p += 2;
int ty = s[p] == 'x' ? 0 : 1;
p++;
auto [l1, r1, n1] = work();
auto [l2, r2, n2] = work();
if (ty == 0) return {l1 + l2, max(n1 + r2, n2 + r1), n1 + n2};
else return {min(l1, l2), r1 + r2 - 1, n1 + n2};
}
void solve() {
cin >> s;
auto [l, r, n] = work();
cout << r - l + 1 << '\n';
}
int main() {
Waimai;
solve();
}
# | 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... |