Submission #912379

#TimeUsernameProblemLanguageResultExecution timeMemory
912379NonozeGarden (JOI23_garden)C++17
30 / 100
3062 ms130644 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define sz(x) (int)(x.size()) #define LSOne(x) (x&(-x)) int n, m, D; vector<int> p, q; vector<int> r, s; vector<bool> xxx(10005, false), yyy(5005, false); bool can(int i) { return (i>=0 && i<2*D+5); } void build(vector<int> &yy, set<int> qq) { for (auto u=qq.begin(); u!=qq.end(); u++) { auto v=++u; --u; if (v==qq.end()) { yy[D-(*u-*qq.begin()+1)]++; } else { yy[*v-*u-1]++; } } } int subtask5() { //vector<pair<int, int>> x; vector<bitset<100005>> x(2*D+5); set<int> y; for (int i=0; i<5005; i++) { int u=yyy[i]; if (u) y.insert(i); } vector<int> yy(2*D+5, 0); build(yy, y); int emply=2*D+4; while (emply>0 && yy[emply]<=0) emply--; int ans=D*D; for (int i=0; i<m; i++) x[r[i]][s[i]]=1, x[r[i]+D][s[i]]=1; for (int a=0; a<D; a++) { auto lsty=y; auto lstyy=yy; auto lstemply=emply; int szy=D-emply; int empl=a+D-1; bitset<100005> bitmask; for (int i=0; i<5005; i++) if (yyy[i]) bitmask[i]=1; bitset<100005> actbitset=bitmask; for (;; empl--) { ans=min(ans, (empl-a+1)*szy); if (xxx[empl]) break; actbitset=bitmask^(x[empl]|bitmask); int value = actbitset._Find_first(); while (value<sz(actbitset)) { bitmask[value]=1; auto tempy=y.lower_bound(value); if (tempy==y.end() || *tempy!=value) { if (tempy==y.end()) { auto prec=y.end(), next=y.begin(); prec--; int act=D-(*prec-*next+1); if (can(act)) yy[act]--; if (can(D-(value-*next+1))) yy[D-(value-*next+1)]++; if (can(value-*prec-1)) yy[value-*prec-1]++; } else if (tempy==y.begin()) { auto prec=y.begin(), next=y.end(); next--; int act=D-(*next-*prec+1); if (can(act)) yy[act]--; if (can(D-(*next-value+1))) yy[D-(*next-value+1)]++; if (can(value-*prec-1)) yy[value-*prec-1]++; } else { auto next=tempy, prec=--tempy; int act=*next-*prec-1; if (can(act)) yy[act]--; if (can(*next-value-1)) yy[*next-value-1]++; if (can(value-*prec-1)) yy[value-*prec-1]++; } y.insert(value); } value=actbitset._Find_next(value); } /*for (auto value: x[empl]) { auto tempy=y.lower_bound(value); if (tempy==y.end() || *tempy!=value) { if (tempy==y.end()) { auto prec=y.end(), next=y.begin(); prec--; int act=D-(*prec-*next+1); if (can(act)) yy[act]--; if (can(D-(value-*next+1))) yy[D-(value-*next+1)]++; if (can(value-*prec-1)) yy[value-*prec-1]++; } else if (tempy==y.begin()) { auto prec=y.begin(), next=y.end(); next--; int act=D-(*next-*prec+1); if (can(act)) yy[act]--; if (can(D-(*next-value+1))) yy[D-(*next-value+1)]++; if (can(value-*prec-1)) yy[value-*prec-1]++; } else { auto next=tempy, prec=--tempy; int act=*next-*prec-1; if (can(act)) yy[act]--; if (can(*next-value-1)) yy[*next-value-1]++; if (can(value-*prec-1)) yy[value-*prec-1]++; } y.insert(value); } }*/ while (emply>0 && yy[emply]<=0) emply--; szy=D-emply; } y=lsty; yy=lstyy; emply=lstemply; } return ans; } int solve() { cin >> n >> m >> D; p.resize(n); q.resize(n); for (int i=0; i<n; i++) { cin >> p[i] >> q[i]; xxx[p[i]]=true; yyy[q[i]]=true; xxx[p[i]+D]=true; } vector<pair<int, int>> temp; for (int i=0; i<m; i++) { int a, b; cin >> a >> b; if (xxx[a] || yyy[b]) continue; temp.push_back({a, b}); } sort(temp.begin(), temp.end()); m=sz(temp); r.clear(), s.clear(); for (auto u: temp) r.push_back(u.first), s.push_back(u.second); return subtask5(); } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout << solve() << endl; return 0; }
#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...