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 target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
#include<bits/stdc++.h>
/**/
//typedef int ll;
typedef long long ll;
typedef unsigned long long ull;
typedef std::string str;
//typedef vector<std::vector<ll>> vv;
/*typedef __int128 vll;
typedef unsigned __int128 uvll;*/
#define llll std::pair<ll , ll>
#define pb push_back
#define pf push_front
#define halo cout << "hello\n"
#define fi first
#define sec second
#define vv(x) std::vector<std::vector<x>>
#define all(a) a.begin() , a.end()
const ll limit = 1e15+7;
const ll ous = 2e5 + 7;
const ll dx[4] = {-1 , 0 , 1 , 0} , dy[4] = {0,1,0,-1};
ll n;std::vector<ll> adj[ous];ll x = 0;
ll ff = 0;std::string s;
ll typ[ous];
void buildadj(ll prv){
ll crt = ff++;
if(s[x++] == '?'){
n++;
typ[crt] = 0;
if(prv < 0){
return;
}
adj[crt].pb(prv);
adj[prv].pb(crt);
return;
}
char c = s[x];
x+=3;
buildadj(crt);
x++;
buildadj(crt);
x++;
if(c == 'i'){
typ[crt] = 1;
}
else{
typ[crt] = 2;
}
if(prv >= 0){
adj[prv].pb(crt);
adj[crt].pb(prv);
}
}
llll dfs(ll crt , ll prv = -1){
if(typ[crt] == 0){
return{1 , n};
}
else if(typ[crt] == 1){
std::vector<llll> v;
for(auto j:adj[crt]){
if(j != prv){
v.pb(dfs(j , crt));
}
}
//std::cout << v.size() << std::endl;
return {std::min(v[0].fi , v[1].fi) , v[0].sec + v[1].sec - n - 1};
}
else{
std::vector<llll> v;
for(auto j:adj[crt]){
if(j != prv){
v.pb(dfs(j , crt));
}
}
//std::cout << v.size() << std::endl;
return {v[0].fi + v[1].fi , std::max(v[0].sec , v[1].sec)};
}
return {0 , 0};
}
void solve(){
std::cin >> s;
buildadj(-1);
llll ans = dfs(0);
std::cout << ans.sec - ans.fi + 1 << "\n";
return;
}
signed main(){
std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);
ll t=1;
//std::cin >> t;
ll o = 1;
while(t--){
solve();
}
return 0;
}/**/
Compilation message (stderr)
Main.cpp:5:78: warning: "/*" within comment [-Wcomment]
5 | #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
|
Main.cpp: In function 'int main()':
Main.cpp:95:8: warning: unused variable 'o' [-Wunused-variable]
95 | ll o = 1;
| ^
# | 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... |