Submission #669066

#TimeUsernameProblemLanguageResultExecution timeMemory
669066ktkeremHomework (CEOI22_homework)C++17
53 / 100
155 ms184036 KiB
/*#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 = 1e6 + 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)); } } assert(v.size() >= 2); //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)); } } assert(v.size() >= 2); //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:97:8: warning: unused variable 'o' [-Wunused-variable]
   97 |     ll o = 1;
      |        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...