This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
int r,c;
cin>>r>>c;
int n;
cin>>n;
vector<pair<int,int>> vpii(n);
for(int i = 0; i < n;i++) {
cin>>vpii[i].first>>vpii[i].second;
vpii[i].first--, vpii[i].second--;
}
int minans = LLONG_MAX;
for(int no = 0; no < r; no++ )
for(int so = 0; so < r; so++) {
set<pair<int,int>> spii;
for(int j = 0; j < n;j++)
for(int k = -no; k <= so; k++) {
int x = vpii[j].first + k;
if(x>=0 && x< r)
spii.emplace(vpii[j].first + k, vpii[j].second);
}
vector<vector<int>> perr(r);
for(auto a:spii)
perr[a.first].push_back(a.second);
int minw = 0, mine = 0, minsum = 0;
for(int i =0 ; i < r;i++) {
sort(perr[i].begin(),perr[i].end());
if(perr[i].empty()) {
goto CANT;
}
minw = max(minw, perr[i].front());
mine = max(mine, c - 1 - perr[i].back());
for(int j = 0 ; j < perr[i].size() - 1; j++) {
minsum = max(minsum, perr[i][j + 1] - perr[i][j] - 1);
}
}
// cout<<no<<' '<<so<<" "<<minw<<" "<<mine<<" "<<minsum<<"\n";
minans = min(minans, no + so + max(minsum, mine + minw));
CANT:;
}
cout<<minans<<"\n";
}
Compilation message (stderr)
cultivation.cpp: In function 'int main()':
cultivation.cpp:39:27: 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]
39 | for(int j = 0 ; j < perr[i].size() - 1; j++) {
| ~~^~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |