Submission #249488

#TimeUsernameProblemLanguageResultExecution timeMemory
249488VEGAnnPoklon (COCI17_poklon7)C++14
120 / 120
618 ms229968 KiB
#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 timeMemoryGrader output
Fetching results...