#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 = 100; 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 |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
11 |
Incorrect |
15 ms |
640 KB |
Output isn't correct |
12 |
Incorrect |
18 ms |
632 KB |
Output isn't correct |
13 |
Incorrect |
74 ms |
1912 KB |
Output isn't correct |
14 |
Incorrect |
150 ms |
3576 KB |
Output isn't correct |
15 |
Incorrect |
147 ms |
1912 KB |
Output isn't correct |
16 |
Incorrect |
521 ms |
9652 KB |
Output isn't correct |
17 |
Execution timed out |
1046 ms |
10972 KB |
Time limit exceeded |
18 |
Execution timed out |
1072 ms |
11332 KB |
Time limit exceeded |
19 |
Execution timed out |
1034 ms |
10992 KB |
Time limit exceeded |
20 |
Execution timed out |
1056 ms |
11384 KB |
Time limit exceeded |