# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
826772 | jamezzz | Garden (JOI23_garden) | C++17 | 3073 ms | 200420 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.
#include <bits/stdc++.h>
using namespace std;
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define INF 1023456789
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
#define maxd 5005
int n,m,d;
int mx[maxd][maxd],my[maxd][maxd];
int main(){
sf("%d%d%d",&n,&m,&d);
for(int i=0;i<n;++i){
int x,y;sf("%d%d",&x,&y);
mx[0][0]=max(mx[0][0],x);
my[0][0]=max(my[0][0],y);
my[0][y+1]=max(my[0][y+1],y+d);
mx[x+1][0]=max(mx[x+1][0],x+d);
}
deque<ii> tmp;
for(int i=0;i<m;++i){
int x,y;sf("%d%d",&x,&y);
tmp.pb({x,y});
}
sort(all(tmp));
for(int i=0;i<d;++i){
for(int j=0;j<d;++j){
if(i!=0){
mx[i][j]=max(mx[i][j],mx[i-1][j]);
my[i][j]=max(my[i][j],my[i-1][j]);
}
if(j!=0){
mx[i][j]=max(mx[i][j],mx[i][j-1]);
my[i][j]=max(my[i][j],my[i][j-1]);
}
}
}
int ans=INF;
for(int y=0;y<d;++y){
deque<ii> dq;
for(auto p:tmp)dq.pb(p);
for(int x=0;x<d;++x){
while(dq.front().fi<x){
ii pr=dq.front();
dq.pop_front();
dq.pb({pr.fi+d,pr.se});
}
int h=my[x][y];
for(int i=sz(dq)-1;i>=0;--i){
if(dq[i].fi<mx[x][y])break;
ans=min(ans,(dq[i].fi-x+1)*(h-y+1));
h=max(h,dq[i].se+(dq[i].se<y)*d);
}
ans=min(ans,(mx[x][y]-x+1)*(h-y+1));
}
}
pf("%d\n",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... |