#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define MP(a,b) make_pair(a,b)
LL W,H;
int N;
LL y[300],x[300];
int main(){
cin >> W >> H >> N;
if(W > 40) return -1;
for(int i=0; i<N; i++){
cin >> x[i] >> y[i];
x[i]--; y[i]--;
}
LL ans = LLONG_MAX;
for(LL l=0; l<=40; l++){
for(LL r=0; r<=40; r++){
vector<LL> memo[40];
for(int i=0; i<N; i++){
for(LL j=max(0LL,x[i]-l); j<=min(W-1,x[i]+r); j++) memo[j].push_back(y[i]);
}
LL u = 0;
LL d = 0;
LL tmp = 0;
for(LL i=0; i<W; i++){
sort(memo[i].begin(), memo[i].end());
if(memo[i].size() == 0){
tmp = LLONG_MAX-100;
break;
}
u = max(u, memo[i][0]);
d = max(d, H-memo[i].back()-1);
for(int j=1; j<memo[i].size(); j++){
tmp = max(tmp, memo[i][j] - memo[i][j-1] - 1);
}
}
ans = min(ans, l+r+max(u+d,tmp));
}
}
cout << ans << endl;
return 0;
}
Compilation message
cultivation.cpp: In function 'int main()':
cultivation.cpp:34:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=1; j<memo[i].size(); j++){
~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
6 ms |
256 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
256 KB |
Output is correct |
14 |
Correct |
3 ms |
256 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
6 ms |
256 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
256 KB |
Output is correct |
14 |
Correct |
3 ms |
256 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
256 KB |
Output is correct |
17 |
Correct |
14 ms |
256 KB |
Output is correct |
18 |
Correct |
52 ms |
384 KB |
Output is correct |
19 |
Correct |
32 ms |
416 KB |
Output is correct |
20 |
Correct |
10 ms |
384 KB |
Output is correct |
21 |
Correct |
54 ms |
384 KB |
Output is correct |
22 |
Correct |
164 ms |
404 KB |
Output is correct |
23 |
Correct |
44 ms |
384 KB |
Output is correct |
24 |
Correct |
291 ms |
604 KB |
Output is correct |
25 |
Correct |
206 ms |
384 KB |
Output is correct |
26 |
Correct |
469 ms |
592 KB |
Output is correct |
27 |
Correct |
525 ms |
720 KB |
Output is correct |
28 |
Correct |
283 ms |
384 KB |
Output is correct |
29 |
Correct |
517 ms |
764 KB |
Output is correct |
30 |
Correct |
476 ms |
604 KB |
Output is correct |
31 |
Correct |
517 ms |
772 KB |
Output is correct |
32 |
Correct |
489 ms |
756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
6 ms |
256 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
256 KB |
Output is correct |
14 |
Correct |
3 ms |
256 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
256 KB |
Output is correct |
17 |
Correct |
14 ms |
256 KB |
Output is correct |
18 |
Correct |
52 ms |
384 KB |
Output is correct |
19 |
Correct |
32 ms |
416 KB |
Output is correct |
20 |
Correct |
10 ms |
384 KB |
Output is correct |
21 |
Correct |
54 ms |
384 KB |
Output is correct |
22 |
Correct |
164 ms |
404 KB |
Output is correct |
23 |
Correct |
44 ms |
384 KB |
Output is correct |
24 |
Correct |
291 ms |
604 KB |
Output is correct |
25 |
Correct |
206 ms |
384 KB |
Output is correct |
26 |
Correct |
469 ms |
592 KB |
Output is correct |
27 |
Correct |
525 ms |
720 KB |
Output is correct |
28 |
Correct |
283 ms |
384 KB |
Output is correct |
29 |
Correct |
517 ms |
764 KB |
Output is correct |
30 |
Correct |
476 ms |
604 KB |
Output is correct |
31 |
Correct |
517 ms |
772 KB |
Output is correct |
32 |
Correct |
489 ms |
756 KB |
Output is correct |
33 |
Correct |
18 ms |
384 KB |
Output is correct |
34 |
Correct |
489 ms |
752 KB |
Output is correct |
35 |
Correct |
477 ms |
556 KB |
Output is correct |
36 |
Correct |
509 ms |
652 KB |
Output is correct |
37 |
Correct |
434 ms |
608 KB |
Output is correct |
38 |
Correct |
524 ms |
704 KB |
Output is correct |
39 |
Correct |
462 ms |
672 KB |
Output is correct |
40 |
Correct |
469 ms |
816 KB |
Output is correct |
41 |
Correct |
361 ms |
616 KB |
Output is correct |
42 |
Correct |
377 ms |
612 KB |
Output is correct |
43 |
Correct |
444 ms |
632 KB |
Output is correct |
44 |
Correct |
526 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
256 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
256 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
6 ms |
256 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
256 KB |
Output is correct |
14 |
Correct |
3 ms |
256 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
256 KB |
Output is correct |
17 |
Correct |
14 ms |
256 KB |
Output is correct |
18 |
Correct |
52 ms |
384 KB |
Output is correct |
19 |
Correct |
32 ms |
416 KB |
Output is correct |
20 |
Correct |
10 ms |
384 KB |
Output is correct |
21 |
Correct |
54 ms |
384 KB |
Output is correct |
22 |
Correct |
164 ms |
404 KB |
Output is correct |
23 |
Correct |
44 ms |
384 KB |
Output is correct |
24 |
Correct |
291 ms |
604 KB |
Output is correct |
25 |
Correct |
206 ms |
384 KB |
Output is correct |
26 |
Correct |
469 ms |
592 KB |
Output is correct |
27 |
Correct |
525 ms |
720 KB |
Output is correct |
28 |
Correct |
283 ms |
384 KB |
Output is correct |
29 |
Correct |
517 ms |
764 KB |
Output is correct |
30 |
Correct |
476 ms |
604 KB |
Output is correct |
31 |
Correct |
517 ms |
772 KB |
Output is correct |
32 |
Correct |
489 ms |
756 KB |
Output is correct |
33 |
Correct |
18 ms |
384 KB |
Output is correct |
34 |
Correct |
489 ms |
752 KB |
Output is correct |
35 |
Correct |
477 ms |
556 KB |
Output is correct |
36 |
Correct |
509 ms |
652 KB |
Output is correct |
37 |
Correct |
434 ms |
608 KB |
Output is correct |
38 |
Correct |
524 ms |
704 KB |
Output is correct |
39 |
Correct |
462 ms |
672 KB |
Output is correct |
40 |
Correct |
469 ms |
816 KB |
Output is correct |
41 |
Correct |
361 ms |
616 KB |
Output is correct |
42 |
Correct |
377 ms |
612 KB |
Output is correct |
43 |
Correct |
444 ms |
632 KB |
Output is correct |
44 |
Correct |
526 ms |
600 KB |
Output is correct |
45 |
Runtime error |
2 ms |
256 KB |
Execution failed because the return code was nonzero |
46 |
Halted |
0 ms |
0 KB |
- |