# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
725903 | Baytoro | Homework (CEOI22_homework) | C++17 | 206 ms | 159208 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 <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define endl '\n'
#define ll long long
#define int long long
void fopn(string name){
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
const ll INF=1e18,mod=1e9+9,N=2e6+5;
vector<int> g[N];
int t[N],m;
pair<int,int> dfs(int x){
if(!g[x].size()) return {1,m};
pair<int,int> a=dfs(g[x][0]);
pair<int,int> b=dfs(g[x][1]);
if(t[x]==1){
int l=min(a.fr,b.fr);
int r=a.sc+b.sc-(m+1);
return {l,r};
}
else{
int l=a.fr+b.fr;
int r=max(a.sc,b.sc);
return {l,r};
}
}
void solve(){
string s;cin>>s;int n=s.size();m=0;
stack<int> st;
int cur=0;
for(int i=0;i<n;i++){
if(s[i]=='n'){
cur++;
if(!st.empty()){
g[st.top()].pb(cur);
}
t[cur]=1;
st.push(cur);
}
if(s[i]=='x'){
cur++;
if(!st.empty()){
g[st.top()].pb(cur);
}
t[cur]=2;
st.push(cur);
}
if(s[i]=='?'){
cur++;m++;
g[st.top()].pb(cur);
}
if(s[i]==')') st.pop();
}
pair<int,int> ans=dfs(1);
cout<<ans.sc-ans.fr+1<<endl;
}
main(){
//fopn("team");
ios;
int T=1;
//cin>>T;
for(int i=1;i<=T;i++){
//cout<<"Case #"<<i<<": ";
solve();
}
}
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... |