답안 #705306

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
705306 2023-03-03T21:36:06 Z rainboy The Kingdom of JOIOI (JOI17_joioi) C
100 / 100
1511 ms 70312 KB
#include <stdio.h>

#define N	2000
#define M	2000
#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; }

int aa[N][M], aa_[N][M], n, m;

int solve_(int d) {
	int i, j, j_, mn, mx;

	mn = INF, mx = -INF;
	for (i = 0; i < n; i++)
		for (j = 0; j < m; j++)
			mn = min(mn, aa_[i][j]), mx = max(mx, aa_[i][j]);
	for (i = 0, j_ = m; i < n; i++) {
		for (j = 0; j < j_; j++)
			if (aa_[i][j] - mn > d) {
				j_ = j;
				break;
			}
		for (j = j_; j < m; j++)
			if (mx - aa_[i][j] > d)
				return 0;
	}
	return 1;
}

int solve(int d) {
	int i, j, jl, jr, u, v, tmp;

	for (i = 0; i < n; i++)
		for (j = 0; j < m; j++)
			aa_[i][j] = aa[i][j];
	for (u = 0; u < 2; u++) {
		for (v = 0; v < 2; v++) {
			if (solve_(d))
				return 1;
			for (i = 0; i < n; i++)
				for (jl = 0, jr = m - 1; jl < jr; jl++, jr--)
					tmp = aa_[i][jl], aa_[i][jl] = aa_[i][jr], aa_[i][jr] = tmp;
		}
		for (i = 0; i < n; i++)
			for (j = 0; j < m; j++)
				aa_[i][j] = -aa_[i][j];
	}
	return 0;
}

int main() {
	int i, j, lower, upper;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++)
		for (j = 0; j < m; j++)
			scanf("%d", &aa[i][j]);
	lower = -1, upper = INF;
	while (upper - lower > 1) {
		int d = (lower + upper) / 2;

		if (solve(d))
			upper = d;
		else
			lower = d;
	}
	printf("%d\n", upper);
	return 0;
}

Compilation message

joioi.c: In function 'main':
joioi.c:56:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
joioi.c:59:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |    scanf("%d", &aa[i][j]);
      |    ^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 292 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 292 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 9 ms 2132 KB Output is correct
17 Correct 11 ms 2356 KB Output is correct
18 Correct 11 ms 2388 KB Output is correct
19 Correct 11 ms 2472 KB Output is correct
20 Correct 10 ms 2132 KB Output is correct
21 Correct 13 ms 2516 KB Output is correct
22 Correct 14 ms 2484 KB Output is correct
23 Correct 14 ms 2568 KB Output is correct
24 Correct 10 ms 2260 KB Output is correct
25 Correct 13 ms 2588 KB Output is correct
26 Correct 15 ms 2476 KB Output is correct
27 Correct 13 ms 2516 KB Output is correct
28 Correct 14 ms 2516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 292 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 9 ms 2132 KB Output is correct
17 Correct 11 ms 2356 KB Output is correct
18 Correct 11 ms 2388 KB Output is correct
19 Correct 11 ms 2472 KB Output is correct
20 Correct 10 ms 2132 KB Output is correct
21 Correct 13 ms 2516 KB Output is correct
22 Correct 14 ms 2484 KB Output is correct
23 Correct 14 ms 2568 KB Output is correct
24 Correct 10 ms 2260 KB Output is correct
25 Correct 13 ms 2588 KB Output is correct
26 Correct 15 ms 2476 KB Output is correct
27 Correct 13 ms 2516 KB Output is correct
28 Correct 14 ms 2516 KB Output is correct
29 Correct 824 ms 52056 KB Output is correct
30 Correct 982 ms 53044 KB Output is correct
31 Correct 1082 ms 54844 KB Output is correct
32 Correct 991 ms 54600 KB Output is correct
33 Correct 870 ms 47780 KB Output is correct
34 Correct 1104 ms 54704 KB Output is correct
35 Correct 1511 ms 70240 KB Output is correct
36 Correct 1163 ms 65028 KB Output is correct
37 Correct 1458 ms 70312 KB Output is correct