#include <stdio.h>
#define N 40
#define M 300
#define INF 0x3f3f3f3f3f3f3f3fLL
long long min(long long a, long long b) { return a < b ? a : b; }
long long max(long long a, long long b) { return a > b ? a : b; }
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 main() {
static int ii[M], jj[M], jj_[M];
int n, m, k, k_, h, i, u, d;
long long l, r, c, ans;
scanf("%d%d%d", &n, &m, &k);
for (h = 0; h < k; h++)
scanf("%d%d", &ii[h], &jj[h]), ii[h]--, jj[h]--;
ans = INF;
for (u = 0; u < n; u++)
for (d = 0; d < n; d++) {
l = r = c = 0;
for (i = 0; i < n; i++) {
k_ = 0;
for (h = 0; h < k; h++)
if (ii[h] - u <= i && i <= ii[h] + d)
jj_[k_++] = jj[h];
if (k_ == 0) {
c = INF;
break;
}
sort(jj_, 0, k_);
l = max(l, jj_[0] - 0), r = max(r, m - 1 - jj_[k_ - 1]);
for (h = 1; h < k_; h++)
c = max(c, jj_[h] - jj_[h - 1] - 1);
}
ans = min(ans, u + d + max(l + r, c));
}
printf("%lld\n", ans);
return 0;
}
Compilation message
cultivation.c: In function 'main':
cultivation.c:40:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | scanf("%d%d%d", &n, &m, &k);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
cultivation.c:42:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | scanf("%d%d", &ii[h], &jj[h]), ii[h]--, jj[h]--;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
288 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
284 KB |
Output is correct |
7 |
Correct |
0 ms |
288 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
288 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
288 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
284 KB |
Output is correct |
7 |
Correct |
0 ms |
288 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
288 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
212 KB |
Output is correct |
18 |
Correct |
25 ms |
212 KB |
Output is correct |
19 |
Correct |
31 ms |
288 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
87 ms |
268 KB |
Output is correct |
22 |
Correct |
212 ms |
268 KB |
Output is correct |
23 |
Correct |
52 ms |
212 KB |
Output is correct |
24 |
Correct |
320 ms |
268 KB |
Output is correct |
25 |
Correct |
266 ms |
264 KB |
Output is correct |
26 |
Correct |
453 ms |
268 KB |
Output is correct |
27 |
Correct |
479 ms |
268 KB |
Output is correct |
28 |
Correct |
291 ms |
212 KB |
Output is correct |
29 |
Correct |
401 ms |
268 KB |
Output is correct |
30 |
Correct |
457 ms |
272 KB |
Output is correct |
31 |
Correct |
466 ms |
268 KB |
Output is correct |
32 |
Correct |
464 ms |
268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
288 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
284 KB |
Output is correct |
7 |
Correct |
0 ms |
288 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
288 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
212 KB |
Output is correct |
18 |
Correct |
25 ms |
212 KB |
Output is correct |
19 |
Correct |
31 ms |
288 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
87 ms |
268 KB |
Output is correct |
22 |
Correct |
212 ms |
268 KB |
Output is correct |
23 |
Correct |
52 ms |
212 KB |
Output is correct |
24 |
Correct |
320 ms |
268 KB |
Output is correct |
25 |
Correct |
266 ms |
264 KB |
Output is correct |
26 |
Correct |
453 ms |
268 KB |
Output is correct |
27 |
Correct |
479 ms |
268 KB |
Output is correct |
28 |
Correct |
291 ms |
212 KB |
Output is correct |
29 |
Correct |
401 ms |
268 KB |
Output is correct |
30 |
Correct |
457 ms |
272 KB |
Output is correct |
31 |
Correct |
466 ms |
268 KB |
Output is correct |
32 |
Correct |
464 ms |
268 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
870 ms |
272 KB |
Output is correct |
35 |
Correct |
769 ms |
332 KB |
Output is correct |
36 |
Correct |
853 ms |
260 KB |
Output is correct |
37 |
Correct |
558 ms |
264 KB |
Output is correct |
38 |
Correct |
845 ms |
268 KB |
Output is correct |
39 |
Correct |
818 ms |
268 KB |
Output is correct |
40 |
Correct |
851 ms |
268 KB |
Output is correct |
41 |
Correct |
666 ms |
264 KB |
Output is correct |
42 |
Correct |
648 ms |
268 KB |
Output is correct |
43 |
Correct |
831 ms |
264 KB |
Output is correct |
44 |
Correct |
721 ms |
264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2071 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2071 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
288 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
284 KB |
Output is correct |
7 |
Correct |
0 ms |
288 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
288 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
212 KB |
Output is correct |
18 |
Correct |
25 ms |
212 KB |
Output is correct |
19 |
Correct |
31 ms |
288 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
87 ms |
268 KB |
Output is correct |
22 |
Correct |
212 ms |
268 KB |
Output is correct |
23 |
Correct |
52 ms |
212 KB |
Output is correct |
24 |
Correct |
320 ms |
268 KB |
Output is correct |
25 |
Correct |
266 ms |
264 KB |
Output is correct |
26 |
Correct |
453 ms |
268 KB |
Output is correct |
27 |
Correct |
479 ms |
268 KB |
Output is correct |
28 |
Correct |
291 ms |
212 KB |
Output is correct |
29 |
Correct |
401 ms |
268 KB |
Output is correct |
30 |
Correct |
457 ms |
272 KB |
Output is correct |
31 |
Correct |
466 ms |
268 KB |
Output is correct |
32 |
Correct |
464 ms |
268 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
870 ms |
272 KB |
Output is correct |
35 |
Correct |
769 ms |
332 KB |
Output is correct |
36 |
Correct |
853 ms |
260 KB |
Output is correct |
37 |
Correct |
558 ms |
264 KB |
Output is correct |
38 |
Correct |
845 ms |
268 KB |
Output is correct |
39 |
Correct |
818 ms |
268 KB |
Output is correct |
40 |
Correct |
851 ms |
268 KB |
Output is correct |
41 |
Correct |
666 ms |
264 KB |
Output is correct |
42 |
Correct |
648 ms |
268 KB |
Output is correct |
43 |
Correct |
831 ms |
264 KB |
Output is correct |
44 |
Correct |
721 ms |
264 KB |
Output is correct |
45 |
Execution timed out |
2071 ms |
212 KB |
Time limit exceeded |
46 |
Halted |
0 ms |
0 KB |
- |