# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1181351 | sleepntsheep | Cultivation (JOI17_cultivation) | C++20 | 2092 ms | 404 KiB |
#include<stdio.h>
#include<algorithm>
#include<vector>
int r,c,n,ans=1e9;
struct pt{int x,y;}p[333];
int main(){
scanf("%d%d%d",&r,&c,&n);
for(int i=0;i<n;++i)scanf("%d%d",&p[i].x,&p[i].y);
std::sort(p,p+n,[](pt&a,pt&b){return a.x-b.x?a.x<b.x:a.y<b.y;});
n=std::unique(p,p+n,[](pt&a,pt&b){return a.x==b.x&&a.y==b.y;})-p;
for(int up=0;up<=r;++up){
for(int dw=0;dw<=r;++dw){
int lef0=0,rig0=0,gapmax=0,ok=1;
auto Chk=[&](int i){
if(!ok)return;
if(i<1)i=1;if(i>r)i=r;
std::vector<int>e;
for(int j=0;j<n;++j)if((p[j].x>=i&&p[j].x-up<=i)||(p[j].x<=i&&p[j].x+dw>=i))
e.push_back(p[j].y);
if(e.empty()){
ok=0;
return;
}
std::sort(e.begin(),e.end());
lef0=std::max(lef0,e[0]-1);
rig0=std::max(rig0,c-e.back());
for(int i=1;i<(int)e.size();++i)
gapmax=std::max(gapmax,e[i]-e[i-1]-1);
};
for(int i=0;ok&&i<n;++i){
Chk(p[i].x-up);
Chk(p[i].x-up-1);
Chk(p[i].x+dw+1);
Chk(p[i].x+dw);
}
if(ok)
ans=std::min(ans,up+dw+std::max(lef0+rig0,gapmax));
}
}
printf("%d",ans);
return 0;
}
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... |