Submission #463801

#TimeUsernameProblemLanguageResultExecution timeMemory
463801rainboyTurnir (COCI17_turnir)C11
100 / 100
449 ms21560 KiB
#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 (stderr)

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]);
      |   ^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...