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

#TimeUsernameProblemLanguageResultExecution timeMemory
864034Danilo21Garden (JOI23_garden)C++17
100 / 100
2083 ms137820 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, mx; vector<int> on, L, R; void Insert(int i){ on[i] = 1; int prev = (i ? i-1 : n-1); int next = (i < n-1 ? i+1 : 0); int l = (on[prev] ? L[prev] : i); int r = (on[next] ? R[next] : i); if (n == 1 || l == next){ mx = n; return; } smax(mx, (r-l + n) % n + 1); R[l] = r; L[r] = l; } int Get() const { return mx; } T(int s){ n = s; mx = 0; on.assign(n, 0); L.resize(n); R.resize(n); } }; const ll LINF = 4e18; const int mxN = 1e6+10, mxD = 5e3+10, INF = 2e9; int n, m, d, a[mxN], b[mxN], is_free[mxD][mxD]; set<int> s; vector<int> K[mxN]; void Solve(){ cin >> n >> m >> d; for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; for (int i = n; i < n+m; i++){ cin >> a[i] >> b[i]; K[a[i]].pb(i); } for (int i = 0; i < d; i++){ for (int j : K[i]) s.insert(b[j]); for (int j = 0; j < d; j++){ if (s.empty()){ is_free[i][j] = j; continue; } is_free[i][j] = *s.rbegin(); if (*s.begin() == j){ s.erase(s.begin()); s.insert(j+d); } } s.clear(); } for (int i = 0; i < n; i++) s.insert(a[i]); for (int i : s) for (int j = 0; j < d; j++) is_free[i][j] = 2*d; s.clear(); for (int i = 0; i < n; i++) s.insert(b[i]); int ans = d*d; for (int i = 0; i < d; i++){ vector<vector<int> > t(2*d); for (int j = 0; j < d; j++) if (is_free[j][i] < 2*d) t[is_free[j][i]].pb(j); auto x = *s.rbegin(); T pool(d); for (int j = 0; j <= x; j++) for (int k : t[j]) pool.Insert(k); smin(ans, (x-i+1) * (d - pool.Get())); for (int j = x+1; j < i+d; j++){ for (int k : t[j]) pool.Insert(k); smin(ans, (j-i+1) * (d - pool.Get())); } if (*s.begin() == i){ s.erase(s.begin()); s.insert(i+d); } } 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...