Submission #669064

#TimeUsernameProblemLanguageResultExecution timeMemory
669064ktkeremHomework (CEOI22_homework)C++17
53 / 100
44 ms48516 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 = 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); } if(x > s.size()){ assert(0); } } 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 'void buildadj(ll)':
Main.cpp:57:10: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     if(x > s.size()){
      |        ~~^~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:100:8: warning: unused variable 'o' [-Wunused-variable]
  100 |     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...