(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #938350

#TimeUsernameProblemLanguageResultExecution timeMemory
938350winter0101Garden (JOI23_garden)C++17
100 / 100
1002 ms9844 KiB
#include<bits/stdc++.h> using namespace std; #define all(fl) fl.begin(),fl.end() #define pb push_back #define fi first #define se second #define for1(i,j,k) for(int i=j;i<=k;i++) #define for2(i,j,k) for(int i=j;i>=k;i--) #define for3(i,j,k,l) for(int i=j;i<=k;i+=l) #define lb lower_bound #define ub upper_bound #define sz(a) (int)a.size() #define pii pair<int,int> #define pli pair<long long,int> #define gcd __gcd #define lcm(x,y) x*y/__gcd(x,y) #define pil pair<int,long long> const int maxn=5e5+9; pii a[maxn],b[maxn]; bool usex[5009],usey[5009]; vector<int>cordx[5009],cord[5009]; bool use[5009]; set<int>add[5009]; int lst[5009]; int haveadd[5009]; bool need[5009]; int nxt[5009],prv[5009]; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); //freopen("temp.INP","r",stdin); //freopen("temp.OUT","w",stdout); int n,m,d; cin>>n>>m>>d; vector<int>crd; for1(i,1,n){ cin>>a[i].fi>>a[i].se; usex[a[i].fi]=usey[a[i].se]=1; crd.pb(a[i].se); need[a[i].fi]=1; } sort(all(crd)); crd.resize(distance(crd.begin(),unique(all(crd)))); for1(i,1,m){ cin>>b[i].fi>>b[i].se; if (usex[b[i].fi]||usey[b[i].se])continue; cordx[b[i].fi].pb(b[i].se); } for2(i,d-1,0){ vector<int>cop; cord[i]=cordx[i]; for (auto v:cordx[i]){ if (use[v])continue; use[v]=1; cop.pb(v); } cordx[i].swap(cop); } int answer=d*d; for1(i,0,d-1)lst[i]=-1; for1(i,0,d-1){ for1(j,0,d-1)haveadd[j]=0; auto real=[&](int v){ if (v<d)return v; return v-d; }; for (auto v:crd){ haveadd[v]++; } int cc=0; for2(j,i-1+d,i){ cc+=need[real(j)]; if (j<d){ for (auto v:cordx[j])haveadd[v]++; } else { for (auto v:add[real(j)])haveadd[v]++; } } for1(j,0,d-1)nxt[j]=j+1; for1(j,0,d-1)prv[j]=j-1; int mn=0,mx=d-1,ans=d; auto del=[&](int v){ if (prv[v]==-1){ mn=nxt[v]; prv[nxt[v]]=-1; return; } if (nxt[v]==d){ mx=prv[v]; if (prv[v]!=-1){ nxt[prv[v]]=d; } return; } ans=min(ans,prv[v]+d-nxt[v]+1); nxt[prv[v]]=nxt[v]; prv[nxt[v]]=prv[v]; return; }; for1(j,0,d-1){ if (!haveadd[j])del(j); } for1(j,i,i-1+d){ cc-=need[real(j)]; if (j<d){ for (auto v:cordx[j]){ haveadd[v]--; if (!haveadd[v])del(v); } } else { for (auto v:add[real(j)]){ haveadd[v]--; if (!haveadd[v])del(v); } } if (!cc)answer=min(answer,(j-i+1)*min(ans,mx-mn+1)); } for (auto v:cord[i]){ if (lst[v]!=i)add[i].insert(v); if (lst[v]!=-1&&lst[v]!=i)add[lst[v]].erase(v); lst[v]=i; } } cout<<answer; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...