Submission #733411

# Submission time Handle Problem Language Result Execution time Memory
733411 2023-04-30T16:37:54 Z rainboy 대표 선수 (KOI11_player) C
20 / 20
359 ms 16436 KB
#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

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 time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 9 ms 680 KB Output is correct
3 Correct 31 ms 1628 KB Output is correct
4 Correct 78 ms 3888 KB Output is correct
5 Correct 87 ms 4660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 2568 KB Output is correct
2 Correct 98 ms 5104 KB Output is correct
3 Correct 140 ms 6508 KB Output is correct
4 Correct 180 ms 7584 KB Output is correct
5 Correct 168 ms 8484 KB Output is correct
6 Correct 206 ms 10000 KB Output is correct
7 Correct 248 ms 12232 KB Output is correct
8 Correct 268 ms 12652 KB Output is correct
9 Correct 323 ms 14444 KB Output is correct
10 Correct 359 ms 16436 KB Output is correct