Submission #472986

#TimeUsernameProblemLanguageResultExecution timeMemory
472986rainboyKarte (COCI18_karte)C11
120 / 120
225 ms7108 KiB
#include <stdio.h> #define N 500000 unsigned int X = 12345; int rand_() { return (X *= 3) >> 1; } void sort(int *aa, int l, int r) { while (l < r) { int i = l, j = l, k = r, a = aa[l + rand_() % (r - l)], tmp; while (j < k) if (aa[j] == a) j++; else if (aa[j] < a) { tmp = aa[i], aa[i] = aa[j], aa[j] = tmp; i++, j++; } else { k--; tmp = aa[j], aa[j] = aa[k], aa[k] = tmp; } sort(aa, l, i); l = k; } } int eval(int *aa, int *bb, int n, long long c) { int i, j, k; i = 0; while (c > n - 1 - i) c -= n - 1 - i++; for (j = 0; j < i; j++) bb[n - 1 - j] = aa[j]; for (j = 0; j < c; j++) bb[j] = aa[i + 1 + j]; bb[c] = aa[i]; for (j = c + 1; j < n - i; j++) bb[j] = aa[i + j]; k = 0; for (i = n - 1; i >= 0; i--) if (k < bb[i]) k++; return k; } int main() { static int aa[N], bb[N]; int n, k, i; long long lower, upper; scanf("%d%d", &n, &k); for (i = 0; i < n; i++) scanf("%d", &aa[i]); sort(aa, 0, n); lower = 0, upper = (long long) n * (n - 1) / 2 + 1; while (upper - lower > 1) { long long c = (lower + upper) / 2; if (eval(aa, bb, n, c) <= k) lower = c; else upper = c; } if (eval(aa, bb, n, lower) != k) printf("-1\n"); else { for (i = 0; i < n; i++) printf("%d ", bb[i]); printf("\n"); } return 0; }

Compilation message (stderr)

karte.c: In function 'main':
karte.c:55:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |  scanf("%d%d", &n, &k);
      |  ^~~~~~~~~~~~~~~~~~~~~
karte.c:57:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...