답안 #463801

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
463801 2021-08-11T19:08:50 Z rainboy Turnir (COCI17_turnir) C
100 / 100
449 ms 21560 KB
#include <stdio.h>

#define N	20

unsigned int X = 12345;

int rand_() {
	return (X *= 3) >> 1;
}

int aa[1 << N];

void sort(int *ii, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;

		while (j < k)
			if (aa[ii[j]] == aa[i_])
				j++;
			else if (aa[ii[j]] < aa[i_]) {
				tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
			}
		sort(ii, l, i);
		l = k;
	}
}

int main() {
	static int ii[1 << N], ll[1 << N];
	int n, h, i, j, l;

	scanf("%d", &n);
	for (i = 0; i < 1 << n; i++) {
		scanf("%d", &aa[i]);
		ii[i] = i;
	}
	sort(ii, 0, 1 << n);
	l = n;
	for (i = 0; i < 1 << n; i = j) {
		int a = aa[ii[i]];

		j = i + 1;
		while (j < 1 << n && aa[ii[j]] == a)
			j++;
		while (l > 0 && (1 << n - l + 1) <= j)
			l--;
		for (h = i; h < j; h++)
			ll[ii[h]] = l;
	}
	for (i = 0; i < 1 << n; i++)
		printf("%d ", ll[i]);
	printf("\n");
	return 0;
}

Compilation message

turnir.c: In function 'main':
turnir.c:49:31: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   49 |   while (l > 0 && (1 << n - l + 1) <= j)
      |                         ~~~~~~^~~
turnir.c:36:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
turnir.c:38:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 11 ms 844 KB Output is correct
6 Correct 25 ms 1552 KB Output is correct
7 Correct 49 ms 2820 KB Output is correct
8 Correct 104 ms 5116 KB Output is correct
9 Correct 235 ms 10916 KB Output is correct
10 Correct 449 ms 21560 KB Output is correct