#pragma GCC optimize("O3,unroll-loops")
#include<cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int C,z=1e9,R, n, x[300], y[300], c[41][41];
int Check(int l, int u, int r, int d) {
memset(c,0,sizeof c);
for (int i = 0; i < n; ++i) {
++c[max(0, x[i]-u)][max(0, y[i]-l)];
--c[max(0, x[i]-u)][min(40,y[i]+r+1)];
--c[min(40,x[i]+d+1)][max(0, y[i]-l)];
++c[min(40,x[i]+d+1)][min(40,y[i]+r+1)];
}
for(int i=1;i<R;++i)c[i][0]+=c[i-1][0];
for(int j=1;j<C;++j)c[0][j]+=c[0][j-1];
for(int i=1;i<R;++i)for(int j=1;j<C;++j)c[i][j]+=c[i-1][j]+c[i][j-1]-c[i-1][j-1];
for(int i=0;i<R;++i)for(int j=0;j<C;++j)if(!c[i][j])return 0;
return 1;
}
int main() {
scanf("%d%d%d", &R, &C, &n);
for (int i = 0; i < n; ++i) scanf("%d%d", x + i, y + i), --x[i], --y[i];
for(int l=0;l<=40;++l)for(int r=0;r<=40;++r){
for(int u=0;u<=40;++u){
int lb=-1,ub=41;
while(ub-lb>1){
int md=lb+(ub-lb)/2;
if(Check(l,u,r,md))ub=md,z=min(z,l+u+r+md);
else lb=md;
}
}
}
printf("%d",z);
}
Compilation message
cultivation.cpp: In function 'int main()':
cultivation.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | scanf("%d%d%d", &R, &C, &n);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
cultivation.cpp:27:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | for (int i = 0; i < n; ++i) scanf("%d%d", x + i, y + i), --x[i], --y[i];
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
412 KB |
Output is correct |
2 |
Correct |
36 ms |
420 KB |
Output is correct |
3 |
Correct |
41 ms |
348 KB |
Output is correct |
4 |
Correct |
37 ms |
348 KB |
Output is correct |
5 |
Correct |
53 ms |
348 KB |
Output is correct |
6 |
Correct |
44 ms |
348 KB |
Output is correct |
7 |
Correct |
45 ms |
344 KB |
Output is correct |
8 |
Correct |
67 ms |
348 KB |
Output is correct |
9 |
Correct |
43 ms |
344 KB |
Output is correct |
10 |
Correct |
49 ms |
344 KB |
Output is correct |
11 |
Correct |
38 ms |
348 KB |
Output is correct |
12 |
Correct |
43 ms |
348 KB |
Output is correct |
13 |
Correct |
42 ms |
348 KB |
Output is correct |
14 |
Correct |
47 ms |
344 KB |
Output is correct |
15 |
Correct |
47 ms |
348 KB |
Output is correct |
16 |
Correct |
44 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
412 KB |
Output is correct |
2 |
Correct |
36 ms |
420 KB |
Output is correct |
3 |
Correct |
41 ms |
348 KB |
Output is correct |
4 |
Correct |
37 ms |
348 KB |
Output is correct |
5 |
Correct |
53 ms |
348 KB |
Output is correct |
6 |
Correct |
44 ms |
348 KB |
Output is correct |
7 |
Correct |
45 ms |
344 KB |
Output is correct |
8 |
Correct |
67 ms |
348 KB |
Output is correct |
9 |
Correct |
43 ms |
344 KB |
Output is correct |
10 |
Correct |
49 ms |
344 KB |
Output is correct |
11 |
Correct |
38 ms |
348 KB |
Output is correct |
12 |
Correct |
43 ms |
348 KB |
Output is correct |
13 |
Correct |
42 ms |
348 KB |
Output is correct |
14 |
Correct |
47 ms |
344 KB |
Output is correct |
15 |
Correct |
47 ms |
348 KB |
Output is correct |
16 |
Correct |
44 ms |
348 KB |
Output is correct |
17 |
Correct |
141 ms |
344 KB |
Output is correct |
18 |
Correct |
320 ms |
404 KB |
Output is correct |
19 |
Correct |
565 ms |
400 KB |
Output is correct |
20 |
Correct |
190 ms |
344 KB |
Output is correct |
21 |
Correct |
481 ms |
344 KB |
Output is correct |
22 |
Correct |
734 ms |
348 KB |
Output is correct |
23 |
Correct |
665 ms |
400 KB |
Output is correct |
24 |
Correct |
822 ms |
348 KB |
Output is correct |
25 |
Correct |
764 ms |
400 KB |
Output is correct |
26 |
Correct |
958 ms |
396 KB |
Output is correct |
27 |
Correct |
943 ms |
348 KB |
Output is correct |
28 |
Correct |
816 ms |
404 KB |
Output is correct |
29 |
Correct |
874 ms |
348 KB |
Output is correct |
30 |
Correct |
946 ms |
348 KB |
Output is correct |
31 |
Correct |
960 ms |
400 KB |
Output is correct |
32 |
Correct |
964 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
412 KB |
Output is correct |
2 |
Correct |
36 ms |
420 KB |
Output is correct |
3 |
Correct |
41 ms |
348 KB |
Output is correct |
4 |
Correct |
37 ms |
348 KB |
Output is correct |
5 |
Correct |
53 ms |
348 KB |
Output is correct |
6 |
Correct |
44 ms |
348 KB |
Output is correct |
7 |
Correct |
45 ms |
344 KB |
Output is correct |
8 |
Correct |
67 ms |
348 KB |
Output is correct |
9 |
Correct |
43 ms |
344 KB |
Output is correct |
10 |
Correct |
49 ms |
344 KB |
Output is correct |
11 |
Correct |
38 ms |
348 KB |
Output is correct |
12 |
Correct |
43 ms |
348 KB |
Output is correct |
13 |
Correct |
42 ms |
348 KB |
Output is correct |
14 |
Correct |
47 ms |
344 KB |
Output is correct |
15 |
Correct |
47 ms |
348 KB |
Output is correct |
16 |
Correct |
44 ms |
348 KB |
Output is correct |
17 |
Correct |
141 ms |
344 KB |
Output is correct |
18 |
Correct |
320 ms |
404 KB |
Output is correct |
19 |
Correct |
565 ms |
400 KB |
Output is correct |
20 |
Correct |
190 ms |
344 KB |
Output is correct |
21 |
Correct |
481 ms |
344 KB |
Output is correct |
22 |
Correct |
734 ms |
348 KB |
Output is correct |
23 |
Correct |
665 ms |
400 KB |
Output is correct |
24 |
Correct |
822 ms |
348 KB |
Output is correct |
25 |
Correct |
764 ms |
400 KB |
Output is correct |
26 |
Correct |
958 ms |
396 KB |
Output is correct |
27 |
Correct |
943 ms |
348 KB |
Output is correct |
28 |
Correct |
816 ms |
404 KB |
Output is correct |
29 |
Correct |
874 ms |
348 KB |
Output is correct |
30 |
Correct |
946 ms |
348 KB |
Output is correct |
31 |
Correct |
960 ms |
400 KB |
Output is correct |
32 |
Correct |
964 ms |
596 KB |
Output is correct |
33 |
Runtime error |
0 ms |
348 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
412 KB |
Output is correct |
2 |
Correct |
36 ms |
420 KB |
Output is correct |
3 |
Correct |
41 ms |
348 KB |
Output is correct |
4 |
Correct |
37 ms |
348 KB |
Output is correct |
5 |
Correct |
53 ms |
348 KB |
Output is correct |
6 |
Correct |
44 ms |
348 KB |
Output is correct |
7 |
Correct |
45 ms |
344 KB |
Output is correct |
8 |
Correct |
67 ms |
348 KB |
Output is correct |
9 |
Correct |
43 ms |
344 KB |
Output is correct |
10 |
Correct |
49 ms |
344 KB |
Output is correct |
11 |
Correct |
38 ms |
348 KB |
Output is correct |
12 |
Correct |
43 ms |
348 KB |
Output is correct |
13 |
Correct |
42 ms |
348 KB |
Output is correct |
14 |
Correct |
47 ms |
344 KB |
Output is correct |
15 |
Correct |
47 ms |
348 KB |
Output is correct |
16 |
Correct |
44 ms |
348 KB |
Output is correct |
17 |
Correct |
141 ms |
344 KB |
Output is correct |
18 |
Correct |
320 ms |
404 KB |
Output is correct |
19 |
Correct |
565 ms |
400 KB |
Output is correct |
20 |
Correct |
190 ms |
344 KB |
Output is correct |
21 |
Correct |
481 ms |
344 KB |
Output is correct |
22 |
Correct |
734 ms |
348 KB |
Output is correct |
23 |
Correct |
665 ms |
400 KB |
Output is correct |
24 |
Correct |
822 ms |
348 KB |
Output is correct |
25 |
Correct |
764 ms |
400 KB |
Output is correct |
26 |
Correct |
958 ms |
396 KB |
Output is correct |
27 |
Correct |
943 ms |
348 KB |
Output is correct |
28 |
Correct |
816 ms |
404 KB |
Output is correct |
29 |
Correct |
874 ms |
348 KB |
Output is correct |
30 |
Correct |
946 ms |
348 KB |
Output is correct |
31 |
Correct |
960 ms |
400 KB |
Output is correct |
32 |
Correct |
964 ms |
596 KB |
Output is correct |
33 |
Runtime error |
0 ms |
348 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |