답안 #298565

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
298565 2020-09-13T07:13:59 Z shrek12357 Poklon (COCI17_poklon7) C++14
12 / 120
1000 ms 17784 KB
#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<int, int> vals[MAXN];
int tot = 0;

int dfs(int src) {
	int 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++) {
		int 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 = 20; i >= 0; i--) {
		if (pow(2, i) > tot) {
			if (used) {
				cout << 0;
			}
		}
		else {
			used = true;
			cout << 1;
			tot -= pow(2, i);
		}
	}
	cout << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Incorrect 1 ms 256 KB Output isn't correct
4 Incorrect 1 ms 256 KB Output isn't correct
5 Incorrect 1 ms 256 KB Output isn't correct
6 Incorrect 1 ms 256 KB Output isn't correct
7 Incorrect 1 ms 384 KB Output isn't correct
8 Incorrect 1 ms 256 KB Output isn't correct
9 Incorrect 1 ms 384 KB Output isn't correct
10 Incorrect 2 ms 288 KB Output isn't correct
11 Incorrect 15 ms 640 KB Output isn't correct
12 Incorrect 18 ms 768 KB Output isn't correct
13 Incorrect 77 ms 2296 KB Output isn't correct
14 Incorrect 149 ms 4344 KB Output isn't correct
15 Incorrect 149 ms 2832 KB Output isn't correct
16 Incorrect 525 ms 12724 KB Output isn't correct
17 Execution timed out 1064 ms 17500 KB Time limit exceeded
18 Execution timed out 1071 ms 17784 KB Time limit exceeded
19 Execution timed out 1082 ms 16456 KB Time limit exceeded
20 Execution timed out 1052 ms 17444 KB Time limit exceeded