Submission #733411

#TimeUsernameProblemLanguageResultExecution timeMemory
733411rainboy대표 선수 (KOI11_player)C11
20 / 20
359 ms16436 KiB
#include <stdio.h> #include <string.h> #define N 1000 #define M 1000 #define INF 0x3f3f3f3f int min(int a, int b) { return a < b ? a : b; } int max(int a, int b) { return a > b ? a : b; } unsigned int X = 12345; int rand_() { return (X *= 3) >> 1; } int aa[N * M], bb[M]; void sort(int *hh, int l, int r) { while (l < r) { int i = l, j = l, k = r, h = hh[l + rand_() % (r - l)], tmp; while (j < k) if (aa[hh[j]] == aa[h]) j++; else if (aa[hh[j]] < aa[h]) { tmp = hh[i], hh[i] = hh[j], hh[j] = tmp; i++, j++; } else { k--; tmp = hh[j], hh[j] = hh[k], hh[k] = tmp; } sort(hh, l, i); l = k; } } int main() { static int hh[N * M]; int n, m, h, h_, i, j, a, ans; scanf("%d%d", &n, &m); for (h = 0; h < n * m; h++) { scanf("%d", &aa[h]); hh[h] = h; } for (i = 0; i < n; i++) { sort(hh, i * m, (i + 1) * m); for (j = 0; j < m; j++) bb[j] = aa[hh[i * m + j]]; memcpy(aa + i * m, bb, m * sizeof *aa); } sort(hh, 0, n * m); a = 0; for (i = 0; i < n; i++) a = max(a, aa[i * m + 0]); ans = INF; for (h = 0; h < n * m; h++) { h_ = hh[h], i = h_ / m, j = h_ % m; ans = min(ans, a - aa[h_]); if (j + 1 == m) break; a = max(a, aa[i * m + j + 1]); } printf("%d\n", ans); return 0; }

Compilation message (stderr)

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