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;
const int nx=305;
int r, c, n, a[nx], b[nx], res=INT_MAX;
vector<int> d[nx];
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>r>>c>>n;
for (int i=1; i<=n; i++) cin>>a[i]>>b[i];
for (int up=0; up<r; up++)
{
for (int dn=0; dn<r; dn++)
{
for (int i=1; i<=r; i++) d[i].clear();
int x=0, g=0, y=0, f=0;
for (int i=1; i<=n; i++) for (int j=max(a[i]-up, 1); j<=min(r, a[i]+dn); j++) d[j].push_back(b[i]);
for (int i=1; i<=r; i++)
{
if (d[i].empty())
{
f=1;
break;
}
sort(d[i].begin(), d[i].end());
x=max(x, d[i][0]-1);
y=max(y, c-d[i].back());
for (int j=1; j<d[i].size(); j++) g=max(g, d[i][j]-d[i][j-1]-1);
}
if (f) continue;
if (x+y>=g) res=min(res, up+dn+x+y);
else res=min(res, up+dn+g);
}
}
cout<<res;
}
Compilation message (stderr)
cultivation.cpp: In function 'int main()':
cultivation.cpp:32:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for (int j=1; j<d[i].size(); j++) g=max(g, d[i][j]-d[i][j-1]-1);
| ~^~~~~~~~~~~~
# | 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... |