#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll,ll>
#define X first
#define Y second
const int maxn = 300 + 5;
const ll inf = 2e16;
int n;
ll R,C;
pii p[maxn];
vector<ll> forup, fordown;
int sz;
map<ll,int> mp;
vector<ll> have[maxn*5];
int main() {
// freopen("try.txt","w",stdout);
scanf("%lld%lld%d",&R,&C,&n);
for(int i=1;i<=n;i++) scanf("%lld%lld",&p[i].X,&p[i].Y);
ll ans = inf;
for(int i=1;i<=n;i++) forup.push_back(p[i].X-1), fordown.push_back(R-p[i].X);
sort(forup.begin(),forup.end());
sort(fordown.begin(),fordown.end());
forup.erase(unique(forup.begin(),forup.end()),forup.end());
fordown.erase(unique(fordown.begin(),fordown.end()),fordown.end());
sort(&p[1],&p[n+1]);
for(auto up : forup) {
for(auto down : fordown) {
mp.clear(); sz = 0;
for(int x=1;x<=n;x++) {
mp[max(1LL,p[x].X-up)];
mp[min(R,p[x].X+down)];
mp[min(R,p[x].X+down+1)];
}
for(auto &t : mp) t.second = ++sz;
for(int i=1;i<=sz;i++) have[i].clear();
for(int x=1;x<=n;x++) {
for(int i=mp[max(1LL,p[x].X-up)];i<=mp[min(R,p[x].X+down)];i++) {
have[i].push_back(p[x].Y);
}
}
for(int row=1;row<=sz;row++) if(have[row].size()>0) sort(have[row].begin(), have[row].end());
ll left = 0, right = 0, gap = 0;
for(int row=1;row<=sz;row++) {
if(have[row].size()==0) continue;
// printf("\trow = %d : ",rec[row]);
// for(auto x : have[row]) printf("%d ",x);
// printf("\n");
left = max(left, *have[row].begin()-1);
right = max(right, C-*have[row].rbegin());
}
for(int row=1;row<=sz;row++) {
for(int i=1;i<have[row].size();i++) gap = max(gap, have[row][i]-have[row][i-1]-1-left-right);
}
ll gaprow = 0;
for(int i=2;i<=n;i++) gaprow = max(gaprow, p[i].X-p[i-1].X-1-up-down);
ans = min(ans, up + down + left + right + gap + gaprow);
// printf("up = %d down = %d (%d) : use %d %d %d\n",up,down,gaprow,left,right,gap);
}
}
printf("%lld",ans);
}
Compilation message
cultivation.cpp: In function 'int main()':
cultivation.cpp:53:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=1;i<have[row].size();i++) gap = max(gap, have[row][i]-have[row][i-1]-1-left-right);
~^~~~~~~~~~~~~~~~~
cultivation.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld%d",&R,&C,&n);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~
cultivation.cpp:19:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=1;i<=n;i++) scanf("%lld%lld",&p[i].X,&p[i].Y);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
488 KB |
Output is correct |
5 |
Correct |
2 ms |
524 KB |
Output is correct |
6 |
Correct |
2 ms |
524 KB |
Output is correct |
7 |
Correct |
2 ms |
548 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
2 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
612 KB |
Output is correct |
12 |
Correct |
2 ms |
612 KB |
Output is correct |
13 |
Correct |
2 ms |
612 KB |
Output is correct |
14 |
Correct |
2 ms |
620 KB |
Output is correct |
15 |
Correct |
2 ms |
624 KB |
Output is correct |
16 |
Correct |
2 ms |
624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
488 KB |
Output is correct |
5 |
Correct |
2 ms |
524 KB |
Output is correct |
6 |
Correct |
2 ms |
524 KB |
Output is correct |
7 |
Correct |
2 ms |
548 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
2 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
612 KB |
Output is correct |
12 |
Correct |
2 ms |
612 KB |
Output is correct |
13 |
Correct |
2 ms |
612 KB |
Output is correct |
14 |
Correct |
2 ms |
620 KB |
Output is correct |
15 |
Correct |
2 ms |
624 KB |
Output is correct |
16 |
Correct |
2 ms |
624 KB |
Output is correct |
17 |
Correct |
3 ms |
624 KB |
Output is correct |
18 |
Correct |
22 ms |
624 KB |
Output is correct |
19 |
Correct |
6 ms |
636 KB |
Output is correct |
20 |
Correct |
2 ms |
636 KB |
Output is correct |
21 |
Correct |
34 ms |
636 KB |
Output is correct |
22 |
Correct |
170 ms |
636 KB |
Output is correct |
23 |
Correct |
3 ms |
636 KB |
Output is correct |
24 |
Correct |
318 ms |
764 KB |
Output is correct |
25 |
Correct |
254 ms |
788 KB |
Output is correct |
26 |
Correct |
523 ms |
788 KB |
Output is correct |
27 |
Correct |
520 ms |
1020 KB |
Output is correct |
28 |
Correct |
290 ms |
1020 KB |
Output is correct |
29 |
Correct |
441 ms |
1020 KB |
Output is correct |
30 |
Correct |
511 ms |
1020 KB |
Output is correct |
31 |
Correct |
526 ms |
1020 KB |
Output is correct |
32 |
Correct |
525 ms |
1020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
488 KB |
Output is correct |
5 |
Correct |
2 ms |
524 KB |
Output is correct |
6 |
Correct |
2 ms |
524 KB |
Output is correct |
7 |
Correct |
2 ms |
548 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
2 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
612 KB |
Output is correct |
12 |
Correct |
2 ms |
612 KB |
Output is correct |
13 |
Correct |
2 ms |
612 KB |
Output is correct |
14 |
Correct |
2 ms |
620 KB |
Output is correct |
15 |
Correct |
2 ms |
624 KB |
Output is correct |
16 |
Correct |
2 ms |
624 KB |
Output is correct |
17 |
Correct |
3 ms |
624 KB |
Output is correct |
18 |
Correct |
22 ms |
624 KB |
Output is correct |
19 |
Correct |
6 ms |
636 KB |
Output is correct |
20 |
Correct |
2 ms |
636 KB |
Output is correct |
21 |
Correct |
34 ms |
636 KB |
Output is correct |
22 |
Correct |
170 ms |
636 KB |
Output is correct |
23 |
Correct |
3 ms |
636 KB |
Output is correct |
24 |
Correct |
318 ms |
764 KB |
Output is correct |
25 |
Correct |
254 ms |
788 KB |
Output is correct |
26 |
Correct |
523 ms |
788 KB |
Output is correct |
27 |
Correct |
520 ms |
1020 KB |
Output is correct |
28 |
Correct |
290 ms |
1020 KB |
Output is correct |
29 |
Correct |
441 ms |
1020 KB |
Output is correct |
30 |
Correct |
511 ms |
1020 KB |
Output is correct |
31 |
Correct |
526 ms |
1020 KB |
Output is correct |
32 |
Correct |
525 ms |
1020 KB |
Output is correct |
33 |
Correct |
2 ms |
1020 KB |
Output is correct |
34 |
Correct |
243 ms |
1020 KB |
Output is correct |
35 |
Correct |
537 ms |
1020 KB |
Output is correct |
36 |
Correct |
545 ms |
1032 KB |
Output is correct |
37 |
Correct |
416 ms |
1032 KB |
Output is correct |
38 |
Correct |
625 ms |
1044 KB |
Output is correct |
39 |
Correct |
517 ms |
1080 KB |
Output is correct |
40 |
Correct |
546 ms |
1080 KB |
Output is correct |
41 |
Correct |
66 ms |
1080 KB |
Output is correct |
42 |
Correct |
279 ms |
1080 KB |
Output is correct |
43 |
Correct |
476 ms |
1080 KB |
Output is correct |
44 |
Correct |
549 ms |
1080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1080 KB |
Output is correct |
2 |
Correct |
11 ms |
1080 KB |
Output is correct |
3 |
Correct |
14 ms |
1080 KB |
Output is correct |
4 |
Correct |
12 ms |
1080 KB |
Output is correct |
5 |
Correct |
13 ms |
1080 KB |
Output is correct |
6 |
Incorrect |
11 ms |
1080 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1080 KB |
Output is correct |
2 |
Correct |
11 ms |
1080 KB |
Output is correct |
3 |
Correct |
14 ms |
1080 KB |
Output is correct |
4 |
Correct |
12 ms |
1080 KB |
Output is correct |
5 |
Correct |
13 ms |
1080 KB |
Output is correct |
6 |
Incorrect |
11 ms |
1080 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
488 KB |
Output is correct |
5 |
Correct |
2 ms |
524 KB |
Output is correct |
6 |
Correct |
2 ms |
524 KB |
Output is correct |
7 |
Correct |
2 ms |
548 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
2 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
612 KB |
Output is correct |
12 |
Correct |
2 ms |
612 KB |
Output is correct |
13 |
Correct |
2 ms |
612 KB |
Output is correct |
14 |
Correct |
2 ms |
620 KB |
Output is correct |
15 |
Correct |
2 ms |
624 KB |
Output is correct |
16 |
Correct |
2 ms |
624 KB |
Output is correct |
17 |
Correct |
3 ms |
624 KB |
Output is correct |
18 |
Correct |
22 ms |
624 KB |
Output is correct |
19 |
Correct |
6 ms |
636 KB |
Output is correct |
20 |
Correct |
2 ms |
636 KB |
Output is correct |
21 |
Correct |
34 ms |
636 KB |
Output is correct |
22 |
Correct |
170 ms |
636 KB |
Output is correct |
23 |
Correct |
3 ms |
636 KB |
Output is correct |
24 |
Correct |
318 ms |
764 KB |
Output is correct |
25 |
Correct |
254 ms |
788 KB |
Output is correct |
26 |
Correct |
523 ms |
788 KB |
Output is correct |
27 |
Correct |
520 ms |
1020 KB |
Output is correct |
28 |
Correct |
290 ms |
1020 KB |
Output is correct |
29 |
Correct |
441 ms |
1020 KB |
Output is correct |
30 |
Correct |
511 ms |
1020 KB |
Output is correct |
31 |
Correct |
526 ms |
1020 KB |
Output is correct |
32 |
Correct |
525 ms |
1020 KB |
Output is correct |
33 |
Correct |
2 ms |
1020 KB |
Output is correct |
34 |
Correct |
243 ms |
1020 KB |
Output is correct |
35 |
Correct |
537 ms |
1020 KB |
Output is correct |
36 |
Correct |
545 ms |
1032 KB |
Output is correct |
37 |
Correct |
416 ms |
1032 KB |
Output is correct |
38 |
Correct |
625 ms |
1044 KB |
Output is correct |
39 |
Correct |
517 ms |
1080 KB |
Output is correct |
40 |
Correct |
546 ms |
1080 KB |
Output is correct |
41 |
Correct |
66 ms |
1080 KB |
Output is correct |
42 |
Correct |
279 ms |
1080 KB |
Output is correct |
43 |
Correct |
476 ms |
1080 KB |
Output is correct |
44 |
Correct |
549 ms |
1080 KB |
Output is correct |
45 |
Correct |
4 ms |
1080 KB |
Output is correct |
46 |
Correct |
11 ms |
1080 KB |
Output is correct |
47 |
Correct |
14 ms |
1080 KB |
Output is correct |
48 |
Correct |
12 ms |
1080 KB |
Output is correct |
49 |
Correct |
13 ms |
1080 KB |
Output is correct |
50 |
Incorrect |
11 ms |
1080 KB |
Output isn't correct |
51 |
Halted |
0 ms |
0 KB |
- |