# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
298570 | shrek12357 | Poklon (COCI17_poklon7) | C++14 | 1052 ms | 12408 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 <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
using namespace std;
const int MAXN = 1e6 + 5;
pair<long long, long long> vals[MAXN];
long long tot = 0;
long long dfs(int src) {
long long val1 = 0, val2 = 0;
if (vals[src].first > 0) {
val1 = dfs(vals[src].first);
}
else {
val1 = -1 * vals[src].first;
}
if (vals[src].second > 0) {
val2 = dfs(vals[src].second);
}
else {
val2 = vals[src].second * -1;
}
tot += max(val1, val2) - min(val1, val2);
return max(val1, val2) * 2;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
long long a, b;
cin >> a >> b;
vals[i + 1] = { a, b };
if (a < 0) {
tot += -1 * a;
}
if (b < 0) {
tot += -1 * b;
}
}
dfs(1);
bool used = false;
for (int i = 50; i >= 0; i--) {
if (pow(2, i) > tot) {
if (used) {
cout << 0;
}
}
else {
used = true;
cout << 1;
tot -= pow(2, i);
}
}
cout << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |