# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
577641 | Ronin13 | Poklon (COCI17_poklon7) | C++14 | 763 ms | 82372 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>
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |