Submission #863753

#TimeUsernameProblemLanguageResultExecution timeMemory
863753Danilo21Garden (JOI23_garden)C++17
30 / 100
3078 ms58292 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, i}); 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 { if (a.empty()) return 0; int ans = (*b.rbegin())[0]; 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; } T(int s) { n = s; } }; 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]; 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]]++; vector<vector<int> > J(2*d); auto x = *s[0].rbegin(); for (auto [j, k] : s[1]){ if (j > x[0]) J[j].pb(k); else cnt[a[k]]--; } T pool(d); for (int j = 0; j < d; j++){ if (cnt[j]) continue; int l = j; while (j+1 < d && !cnt[j+1]) j++; pool.Insert(l, j); } smin(ans, (x[0]-i+1) * (d - pool.Get())); for (int j = x[0]+1; j < i+d; j++){ if (J[j].empty()) continue; for (int k : J[j]){ 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...