# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
865537 | mychecksedad | Homework (CEOI22_homework) | C++17 | 173 ms | 205152 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.
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 3e6+100, M = 1e5+10, K = 52, MX = 30;
vector<int> g[N];
vector<int> tp;
int sz[N];
pair<int, int> dfs(int v){
sz[v] = tp[v] == 2;
if(tp[v] == 2) return {1, 1};
pair<int, int> x = dfs(g[v][0]);
pair<int, int> y = dfs(g[v][1]);
// cout << g[v][0] << ": " << x.first << ' ' << x.second << '|' << g[v][1] << ": " << y.first << ' ' << y.second << '\n';
sz[v] += sz[g[v][0]];
sz[v] += sz[g[v][1]];
if(tp[v] == 0)
return {min(x.first, y.first), x.second + y.second - 1};
return {x.first + y.first, max(sz[g[v][0]] + y.second, x.second + sz[g[v][1]])};
}
string s;
void solve(){
cin >> s;
int n = 0, mx = 0, mn = 0;
int cur = 1;
tp.resize(s.size()+2);
vector<int> last;
for(int i = 0 ; i < s.length(); ++i){
if(s[i] == '?'){
tp[cur] = 2;
if(!last.empty()){
g[last.back()].pb(cur);
}
++cur;
}else if(s[i] == '('){
if(!last.empty()){
g[last.back()].pb(cur);
}
if(s[i - 1] == 'n') tp[cur] = 0;
else if(s[i - 1] == 'x') tp[cur] = 1;
last.pb(cur);
++cur;
}else if(s[i] == ')'){
last.pop_back();
}
}
auto R = dfs(1);
cout << R.second-R.first+1;
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int tt = 1, aa;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// cin >> tt;
while(tt--){
solve();
// en;
}
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
return 0;
}
Compilation message (stderr)
# | 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... |