Submission #465374

#TimeUsernameProblemLanguageResultExecution timeMemory
465374rainboyPoklon (COCI17_poklon7)C11
120 / 120
295 ms77256 KiB
#include <stdio.h>

#define N	1000000

int max(int a, int b) { return a > b ? a : b; }

int ll[N + 1], rr[N + 1], cc[N + 1], mx[N + 1]; long long sum;

void dfs(int i, int d) {
	if (i <= 0) {
		sum += -i;
		mx[d] = max(mx[d], -i);
	} else
		dfs(ll[i], d + 1), dfs(rr[i], d + 1);
}

void print(int a) {
	if (a == 0)
		return;
	print(a / 2);
	printf("%d", a % 2);
}

int main() {
	int n, i, d, d_;

	scanf("%d", &n);
	for (i = 1; i <= n; i++)
		scanf("%d%d", &ll[i], &rr[i]);
	dfs(1, 0);
	d_ = 0;
	for (d = 1; d <= n; d++)
		if ((mx[d_] >> d - d_) < mx[d])
			d_ = d;
	if (mx[d_] == 0)
		printf("0\n");
	else {
		print(mx[d_]);
		while (d_--)
			printf("0");
		printf("\n");
	}
	return 0;
}

Compilation message (stderr)

poklon.c: In function 'main':
poklon.c:33:20: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   33 |   if ((mx[d_] >> d - d_) < mx[d])
      |                  ~~^~~~
poklon.c:27:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
poklon.c:29:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |   scanf("%d%d", &ll[i], &rr[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...