# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
405340 | Aryan_Raina | Poklon (COCI17_poklon7) | C++14 | 801 ms | 221680 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>
using namespace std;
#define int int64_t
#define ld long double
#define ar array
const int INF = 1e17;
const int MOD = 1e9+7;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int N; cin >> N;
vector<ar<int,2>> adj(N);
for (auto &i : adj) {
cin >> i[0] >> i[1];
if (i[0] > 0) --i[0];
if (i[1] > 0) --i[1];
}
vector<string> remdi;
function<int(int)> dfs = [&](int u)->int {
if (u < 0) {
remdi.push_back("");
for (int i = -u; i; i >>= 1) remdi.back() += '0' + (i & 1);
reverse(remdi.back().begin(), remdi.back().end());
return (int) remdi.size() - 1;
}
int lc = dfs(adj[u][0]), rc = dfs(adj[u][1]), ans = lc;
if (remdi[lc].size() == remdi[rc].size()) {
for (int i = 0; i < remdi[lc].size(); i++) {
if (remdi[lc][i] ^ remdi[rc][i]) {
ans = (remdi[lc][i] - '0') ? lc : rc;
break;
}
}
} else {
ans = (remdi[lc].size() > remdi[rc].size()) ? lc : rc;
}
remdi[ans] += '0';
return ans;
};
cout << remdi[dfs(0)] << '\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |