#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(i+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=1;R<r;R++){
for(int C=1;C<r;C++){
ans=min(ans,R+C+check(R,C));
}
}
cout << ans << '\n';
}
Compilation message
cultivation.cpp: In lambda function:
cultivation.cpp:28: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]
28 | for(int x=1;x<lines[i].size();x++) {
| ~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |