(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 #814121

#TimeUsernameProblemLanguageResultExecution timeMemory
814121arnold518Garden (JOI23_garden)C++17
100 / 100
1580 ms15084 KiB
#pragma GCC optimize ("O3") #pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC target ("avx,avx2,fma") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 5e5; const int MAXD = 5000; const ll INF = 1e18; int N, M, D; vector<int> B[MAXD+10]; int P[MAXD+10], Q[MAXD*2+10]; vector<pii> V[MAXD+10]; set<int> C[MAXD*2+10]; struct Data { int L[MAXD+10], R[MAXD+10], cnt=0, val=0; void init() { for(int i=0; i<D; i++) L[i]=-1, R[i]=-1; cnt=0; val=0; } void insert(int x) { L[x]=R[x]=x; cnt++; } void init2() { int bef=-1; for(int i=0; i<D; i++) { if(L[i]!=i) continue; if(bef!=-1) val=max(val, i-bef); bef=i; } for(int i=0; i<D; i++) { if(L[i]!=i) continue; val=max(val, i+D-bef); break; } for(int i=1; i<D; i++) if(L[i]!=i) L[i]=L[i-1]; if(L[0]!=0) L[0]=L[D-1]; for(int i=1; i<D; i++) if(L[i]!=i) L[i]=L[i-1]; for(int i=D-2; i>=0; i--) if(R[i]!=i) R[i]=R[i+1]; if(R[D-1]!=D-1) R[D-1]=R[0]; for(int i=D-2; i>=0; i--) if(R[i]!=i) R[i]=R[i+1]; } int FindL(int x) { if(x==-1) return FindL(D-1); if(x==L[x]) return x; return L[x]=FindL(L[x]); } int FindR(int x) { if(x==D) return FindR(0); if(x==R[x]) return x; return R[x]=FindR(R[x]); } void Delete(int x) { cnt--; assert(L[x]==x); assert(R[x]==x); int p=FindL(x-1), q=FindR(x+1); if(p<q) val=max(val, q-p); else val=max(val, q+D-p); L[x]=x-1; if(x==0) L[x]=D-1; R[x]=x+1; if(x==D-1) R[x]=0; } int query() { if(cnt<=1) return 1; else return D-val+1; } }DB; ll ans=INF; int main() { scanf("%d%d%d", &N, &M, &D); for(int i=1; i<=N; i++) { int y, x; scanf("%d%d", &x, &y); P[x]=1; Q[y]=1; Q[y+D]=1; } for(int i=1; i<=M; i++) { int y, x; scanf("%d%d", &x, &y); if(P[x]) continue; B[x].push_back(y); } for(int i=0; i<D; i++) { if(B[i].empty()) continue; sort(B[i].begin(), B[i].end()); B[i].erase(unique(B[i].begin(), B[i].end()), B[i].end()); V[0].push_back({B[i].back(), i+1}); int t=B[i].back(); for(auto it : B[i]) { V[it+1].push_back({t, -i}); V[it+1].push_back({it+D, i+1}); t=it+D; } } for(int i=0; i<D; i++) { DB.init(); for(int j=0; j<D; j++) if(P[j]) DB.insert(j); int val=i; for(int j=D+i-1; j>=i; j--) if(Q[j]) { val=j; break; } for(auto [y, x] : V[i]) { if(x>0) C[y].insert(x-1); else C[y].erase(-x); } for(int j=val; j<D+i; j++) for(auto it : C[j]) DB.insert(it); DB.init2(); for(int j=val; j<D+i; j++) { for(auto it : C[j]) DB.Delete(it); ans=min(ans, (ll)DB.query()*(j-i+1)); } } printf("%lld\n", ans); }

Compilation message (stderr)

garden.cpp: In function 'int main()':
garden.cpp:98:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |     scanf("%d%d%d", &N, &M, &D);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
garden.cpp:102:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |         scanf("%d%d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~
garden.cpp:108:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  108 |         scanf("%d%d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~
#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...