Submission #577641

# Submission time Handle Problem Language Result Execution time Memory
577641 2022-06-15T07:14:54 Z Ronin13 Poklon (COCI17_poklon7) C++14
120 / 120
763 ms 82372 KB
#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
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 8 ms 852 KB Output is correct
12 Correct 9 ms 944 KB Output is correct
13 Correct 38 ms 3484 KB Output is correct
14 Correct 72 ms 6796 KB Output is correct
15 Correct 82 ms 4988 KB Output is correct
16 Correct 259 ms 20828 KB Output is correct
17 Correct 592 ms 47540 KB Output is correct
18 Correct 614 ms 49336 KB Output is correct
19 Correct 758 ms 54924 KB Output is correct
20 Correct 763 ms 82372 KB Output is correct