Submission #863742

#TimeUsernameProblemLanguageResultExecution timeMemory
863742Danilo21Garden (JOI23_garden)C++17
0 / 100
3049 ms58324 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define pb push_back #define fi first #define se second #define en '\n' #define sp ' ' #define tb '\t' #define ri(n) int n; cin >> n #define rl(n) ll n; cin >> n #define rs(s) string s; cin >> s #define rc(c) char c; cin >> c #define rv(v) for (auto &x : v) cin >> x #define pven(v) for (auto x : v) cout << x << en #define pv(v) for (auto x : v) cout << x << sp; cout << en #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define yes cout << "YES" << en #define no cout << "NO" << en #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) #define ssort(a, b) if (a < b) swap(a, b) #define bitcnt(a) (__builtin_popcountll(a)) #define bithigh(a) (63-__builtin_clzll(a)) #define lg bithigh #define highpow(a) (1LL << (ll)lg(a)) using namespace std; struct T{ int n; set<array<int, 2> > a, b; void Insert(int l, int r){ a.insert({l, r}); b.insert({r-l+1, l}); } void Erase(int l, int r){ a.erase({l, r}); b.erase({r-l+1, l}); } void Insert(int i){ int l = i, r = i; vector<array<int, 2> > er; auto it = a.lower_bound({i, 0}); if (it != a.end() && (*it)[0] == i+1){ r = (*it)[1]; er.pb(*it); } if (it != a.begin()){ it--; if ((*it)[1] == i-1){ l = (*it)[0]; er.pb(*it); } } for (auto [l1, r1] : er) Erase(l1, r1); Insert(l, r); } int Get() const { int ans = (*b.rbegin())[0]; if (a.size()){ auto x = *a.begin(), y = *a.rbegin(); if (x[0] == 0 && y[1] == n-1) smax(ans, x[1] - x[0] + 1 + y[1] - y[0] + 1); } return ans; } void Assign(int s) { n = s; a.clear(); b.clear(); } void Print() const { cout << "Print T: \n"; for (auto [l, r] : a) cout << l << sp << r << en; cout << en; } }; const ll LINF = 4e18; const int mxN = 1e6+10, INF = 2e9; int n, m, d, a[mxN], b[mxN]; vector<int> row[mxN]; set<array<int, 2> > s[2]; T pool; void Solve(){ cin >> n >> m >> d; for (int i = 0; i < n; i++){ cin >> a[i] >> b[i]; row[b[i]].pb(i); s[0].insert({b[i], i}); } for (int i = n; i < n+m; i++){ cin >> a[i] >> b[i]; row[b[i]].pb(i); s[1].insert({b[i], i}); } int ans = d*d; for (int i = 0; i < d; i++){ vector<int> cnt(d, 0); for (int j = 0; j < n+m; j++) cnt[a[j]]++; pool.Assign(d); for (int j = 0; j < d; j++) if (!cnt[j]) pool.Insert(j); map<int, vector<int> > J; auto x = *s[0].rbegin(); for (auto [j, k] : s[1]){ if (j > x[0]) J[j].pb(k); else{ cnt[a[k]]--; if (!cnt[a[k]]) pool.Insert(a[k]); } } smin(ans, (x[0]-i+1) * (d - pool.Get())); for (auto [j, v] : J){ for (int k : v){ cnt[a[k]]--; if (!cnt[a[k]]) pool.Insert(a[k]); } smin(ans, (j-i+1) * (d - pool.Get())); } for (int j : row[i]){ if (j < n){ s[0].erase({i, j}); s[0].insert({i+d, j}); } else{ s[1].erase({i, j}); s[1].insert({i+d, j}); } } } cout << ans << en; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cerr.tie(0); cout << setprecision(12) << fixed; cerr << setprecision(12) << fixed; cerr << "Started!" << endl; int t = 1; //cin >> t; while (t--) Solve(); 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...