Submission #577641

#TimeUsernameProblemLanguageResultExecution timeMemory
577641Ronin13Poklon (COCI17_poklon7)C++14
120 / 120
763 ms82372 KiB
#include <bits/stdc++.h> #define ll long long #define ull unsigned ll #define f first #define s second #define pii pair<int,int> #define pll pair<ll,ll> #define pb push_back #define epb emplace_back using namespace std; const int NMAX = 1e6 + 1; pll a[NMAX]; pll comp(pll a, pll b){ if(a.s > b.s) return {a.f, a.s + 1}; if(a.s == b.s){ if(a.f > b.f) return {a.f, a.s + 1}; return {b.f, b.s + 1}; } return {b.f, b.s + 1}; } ll l[NMAX], r[NMAX]; pll ans[NMAX]; pll solve(int v){ pll x, y; if(l[v] > 0) x = solve(l[v]); else x = {-l[v], 0}; if(r[v] > 0) y = solve(r[v]); else y = {-r[v], 0}; if(x.f * 2 < (1LL << 31) && x.s) x.f *= 2, x.s--; if(y.f * 2 < (1LL << 31) && y.s) y.f *=2, y.s--; ans[v] = comp(x, y); if(ans[v].f * 2 < (1LL << 31) && ans[v].s) ans[v].f *=2, ans[v].s--; return ans[v]; } int main(){ int n; cin >> n; for(int i = 1; i <= n; ++i) cin >> l[i] >> r[i]; solve(1); string s = ""; while(ans[1].f){ int x = ans[1].f % 2; char c = '0' + x; s += c; ans[1].f /= 2; } reverse(s.begin(), s.end()); while(ans[1].s){ s += '0'; ans[1].s--; } cout << s; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...