Submission #249488

# Submission time Handle Problem Language Result Execution time Memory
249488 2020-07-15T06:45:12 Z VEGAnn Poklon (COCI17_poklon7) C++14
120 / 120
618 ms 229968 KB
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
using namespace std;
const int N = 1000100;
int lf[N], rt[N], n;

string calc(int pos){
    string l, r;

    if (lf[pos] < 0){
        int vl = -lf[pos];
        l = "";

        while (vl > 0){
            l += char((vl & 1) + '0');
            vl >>= 1;
        }

        reverse(all(l));
    } else l = calc(lf[pos]);

    if (rt[pos] < 0){
        int vl = -rt[pos];
        r = "";

        while (vl > 0){
            r += char((vl & 1) + '0');
            vl >>= 1;
        }

        reverse(all(r));
    } else r = calc(rt[pos]);

    if (sz(r) == sz(l)){
        bool fi = 1;

        for (int i = 0; i < sz(l) && fi; i++){
            if (r[i] == l[i]) continue;

            if (l[i] < r[i]) fi = 0;

            break;
        }

        if (fi){
            l += "0";
            return l;
        } else {
            r += "0";
            return r;
        }
    } else if (sz(r) > sz(l)){
        r += "0";
        return r;
    } else {
        l += "0";
        return l;
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n;

    for (int i = 1; i <= n; i++)
        cin >> lf[i] >> rt[i];

    string res = calc(1);

    cout << res;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 7 ms 1792 KB Output is correct
12 Correct 8 ms 1536 KB Output is correct
13 Correct 32 ms 7552 KB Output is correct
14 Correct 63 ms 15612 KB Output is correct
15 Correct 54 ms 2808 KB Output is correct
16 Correct 202 ms 39288 KB Output is correct
17 Correct 472 ms 79096 KB Output is correct
18 Correct 468 ms 89464 KB Output is correct
19 Correct 573 ms 52088 KB Output is correct
20 Correct 618 ms 229968 KB Output is correct