#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e15;
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int r,c,n;
cin >> r >> c >> n;
vector<pair<int,int>> points(n);
for(auto&[a,b]:points)cin>>a>>b;
auto check = [&](int U,int L){
vector<vector<int>> lines(r+1);
for(auto&[x,y]:points) {
for(int i=max(x-L,1ll);i<=min(x+U,r);i++)
lines[i].emplace_back(y);
}
int left_maxi = 0;
int right_maxi = 0;
int tot_maxi = 0;
for(int i=1;i<=r;i++) {
sort(lines[i].begin(),lines[i].end());
if(lines[i].empty())return INF;
left_maxi=max(left_maxi,lines[i].front()-1);
right_maxi=max(right_maxi,c-lines[i].back());
for(int x=1;x<lines[i].size();x++) {
tot_maxi=max(tot_maxi,lines[i][x]-lines[i][x-1]-1);
}
}
return max(left_maxi+right_maxi,tot_maxi);
};
int ans = r+c;
for(int R=0;R<r;R++){
for(int C=0;C<r;C++){
ans=min(ans,R+C+check(R,C));
}
}
cout << ans << '\n';
}
Compilation message
cultivation.cpp: In lambda function:
cultivation.cpp:29:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int x=1;x<lines[i].size();x++) {
| ~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
456 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
456 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
10 ms |
348 KB |
Output is correct |
19 |
Correct |
19 ms |
480 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
30 ms |
348 KB |
Output is correct |
22 |
Correct |
81 ms |
344 KB |
Output is correct |
23 |
Correct |
20 ms |
344 KB |
Output is correct |
24 |
Correct |
152 ms |
576 KB |
Output is correct |
25 |
Correct |
121 ms |
344 KB |
Output is correct |
26 |
Correct |
298 ms |
664 KB |
Output is correct |
27 |
Correct |
269 ms |
644 KB |
Output is correct |
28 |
Correct |
133 ms |
512 KB |
Output is correct |
29 |
Correct |
246 ms |
636 KB |
Output is correct |
30 |
Correct |
265 ms |
640 KB |
Output is correct |
31 |
Correct |
275 ms |
644 KB |
Output is correct |
32 |
Correct |
278 ms |
656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
456 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
10 ms |
348 KB |
Output is correct |
19 |
Correct |
19 ms |
480 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
30 ms |
348 KB |
Output is correct |
22 |
Correct |
81 ms |
344 KB |
Output is correct |
23 |
Correct |
20 ms |
344 KB |
Output is correct |
24 |
Correct |
152 ms |
576 KB |
Output is correct |
25 |
Correct |
121 ms |
344 KB |
Output is correct |
26 |
Correct |
298 ms |
664 KB |
Output is correct |
27 |
Correct |
269 ms |
644 KB |
Output is correct |
28 |
Correct |
133 ms |
512 KB |
Output is correct |
29 |
Correct |
246 ms |
636 KB |
Output is correct |
30 |
Correct |
265 ms |
640 KB |
Output is correct |
31 |
Correct |
275 ms |
644 KB |
Output is correct |
32 |
Correct |
278 ms |
656 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
318 ms |
652 KB |
Output is correct |
35 |
Correct |
283 ms |
656 KB |
Output is correct |
36 |
Correct |
303 ms |
652 KB |
Output is correct |
37 |
Correct |
187 ms |
628 KB |
Output is correct |
38 |
Correct |
303 ms |
656 KB |
Output is correct |
39 |
Correct |
279 ms |
644 KB |
Output is correct |
40 |
Correct |
309 ms |
664 KB |
Output is correct |
41 |
Correct |
138 ms |
636 KB |
Output is correct |
42 |
Correct |
178 ms |
640 KB |
Output is correct |
43 |
Correct |
247 ms |
852 KB |
Output is correct |
44 |
Correct |
293 ms |
652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
456 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
10 ms |
348 KB |
Output is correct |
19 |
Correct |
19 ms |
480 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
30 ms |
348 KB |
Output is correct |
22 |
Correct |
81 ms |
344 KB |
Output is correct |
23 |
Correct |
20 ms |
344 KB |
Output is correct |
24 |
Correct |
152 ms |
576 KB |
Output is correct |
25 |
Correct |
121 ms |
344 KB |
Output is correct |
26 |
Correct |
298 ms |
664 KB |
Output is correct |
27 |
Correct |
269 ms |
644 KB |
Output is correct |
28 |
Correct |
133 ms |
512 KB |
Output is correct |
29 |
Correct |
246 ms |
636 KB |
Output is correct |
30 |
Correct |
265 ms |
640 KB |
Output is correct |
31 |
Correct |
275 ms |
644 KB |
Output is correct |
32 |
Correct |
278 ms |
656 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
318 ms |
652 KB |
Output is correct |
35 |
Correct |
283 ms |
656 KB |
Output is correct |
36 |
Correct |
303 ms |
652 KB |
Output is correct |
37 |
Correct |
187 ms |
628 KB |
Output is correct |
38 |
Correct |
303 ms |
656 KB |
Output is correct |
39 |
Correct |
279 ms |
644 KB |
Output is correct |
40 |
Correct |
309 ms |
664 KB |
Output is correct |
41 |
Correct |
138 ms |
636 KB |
Output is correct |
42 |
Correct |
178 ms |
640 KB |
Output is correct |
43 |
Correct |
247 ms |
852 KB |
Output is correct |
44 |
Correct |
293 ms |
652 KB |
Output is correct |
45 |
Runtime error |
2 ms |
600 KB |
Execution killed with signal 6 |
46 |
Halted |
0 ms |
0 KB |
- |