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>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ff first
#define ss second
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define F0R(i, x) FOR(i, 0, x)
#define FORd(i, a, b) for(int i = (b)-1; i >= (a); i--)
#define F0Rd(i, x) FORd(i, 0, x)
#define ckif(a, b, c) ((c) ? (a) : (b))
const int MAX_N = 1e7+69;
const ll MOD = 1000000007;
const ll INF = 1e18;
int n;
int ql[MAX_N], qr[MAX_N], sz[MAX_N];
string s;
int dfs(int idx){
if(s[idx] == '?'){
idx++;
sz[idx] = 1;
return idx;
}
int num = 0;
if(s[idx+1] == 'a') num = 1;
idx += 4;
idx = dfs(idx);
int ql1 = ql[idx], qr1 = qr[idx], sz1 = sz[idx];
idx++;
idx = dfs(idx);
int ql2 = ql[idx], qr2 = qr[idx], sz2 = sz[idx];
idx++;
sz[idx] = sz1+sz2;
if(num){
ql[idx] = ql1+ql2+1;
qr[idx] = max(sz1+qr2, sz2+qr1);
} else{
ql[idx] = min(ql1, ql2);
qr[idx] = qr1+qr2;
}
return idx;
}
int main(int argc, const char * argv[]){
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
cin >> s;
int x = dfs(0);
cout << qr[x]-ql[x]+1 << '\n';
return 0;
}
# | 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... |