Submission #813253

#TimeUsernameProblemLanguageResultExecution timeMemory
813253arnold518Garden (JOI23_garden)C++17
30 / 100
3071 ms1788 KiB
#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 { set<int> S; multiset<int> S2; void init() { S.clear(); S2.clear(); } void insert(int x) { if(S.count(x)) return; S.insert(x); if(S.size()==2) { int p=*S.begin(), q=*next(S.begin()); S2.insert(q-p); S2.insert(D+p-q); } else if(S.size()>2) { auto it=S.find(x); int p, q; if(it!=S.begin()) p=*prev(it); else p=*prev(S.end())-D; if(next(it)!=S.end()) q=*next(it); else q=*S.begin()+D; S2.erase(S2.find(q-p)); S2.insert(x-p); S2.insert(q-x); } } int query() { if(S.size()<=1) return 1; else return D-*prev(S2.end())+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", &y, &x); P[x]=1; Q[y]=1; Q[y+D]=1; } for(int i=1; i<=M; i++) { int y, x; scanf("%d%d", &y, &x); 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=D+i-1; j>=val; j--) { ans=min(ans, (ll)DB.query()*(j-i+1)); for(auto it : C[j]) DB.insert(it); } } printf("%lld\n", ans); }

Compilation message (stderr)

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