# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
46513 | ikura355 | Cultivation (JOI17_cultivation) | C++14 | 2063 ms | 764 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//30 pts. #2
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define X first
#define Y second
const int maxn = 300 + 5;
const int inf = 1e9;
int n,R,C;
pii p[maxn];
vector<int> have[45];
vector<int> forup, fordown;
int main() {
scanf("%d%d%d",&R,&C,&n);
for(int i=1;i<=n;i++) scanf("%d%d",&p[i].X,&p[i].Y);
//fix up and down (R<=40)
int ans = inf;
for(int i=1;i<=n;i++) forup.push_back(p[i].X-1), fordown.push_back(R-p[i].X);
for(auto up : forup) {
for(auto down : fordown) {
for(int row=1;row<=R;row++) have[row].clear();
for(int x=1;x<=n;x++) {
for(int i=max(1,p[x].X-up);i<=min(R,p[x].X+down);i++) {
have[i].push_back(p[x].Y);
}
}
for(int row=1;row<=R;row++) sort(have[row].begin(), have[row].end());
int left = 0, right = 0, gap = 0;
int gaprow = 0, con = 0;
for(int row=1;row<=R;row++) {
if(have[row].size()==0) {
con++;
gaprow = max(gaprow, con);
}
else {
con = 0;
left = max(left, *have[row].begin()-1);
right = max(right, C-*have[row].rbegin());
}
}
for(int row=1;row<=R;row++) {
for(int i=1;i<have[row].size();i++) gap = max(gap, have[row][i]-have[row][i-1]-1-left-right);
}
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("%d",ans);
}
Compilation message (stderr)
# | 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... |