Submission #825294

#TimeUsernameProblemLanguageResultExecution timeMemory
825294ikaurovGarden (JOI23_garden)C++17
0 / 100
3016 ms25372 KiB
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define all(arr) (arr).begin(), (arr).end() #define ll long long #define ld long double #define pb push_back #define sz(x) (int)(x).size() #define fi first #define se second #define endl '\n' const int D = 5005; int d; int calc(int x){ x %= d; if (x < 0) x += d; return x; } struct linkedlist{ int n; int maxval; vector<int> nxt, prv, val; int calcdist(int i){ if (nxt[i] > i) return val[nxt[i]] - val[i]; else return val[nxt[i]] - val[i] + d; } linkedlist(){}; linkedlist(vector<pair<int, int>>& a){ n = sz(a); nxt.resize(n); prv.resize(n); val.resize(n); iota(all(nxt), 1); nxt[n - 1] = 0; iota(all(prv), -1); prv[0] = n - 1; for (int i = 0; i < n; i++) val[i] = a[i].fi; maxval = 0; for (int i = 0; i < n; i++){ maxval = max(maxval, calcdist(i)); } }; void del(int idx){ if (nxt[idx] == idx) return; nxt[prv[idx]] = nxt[idx]; prv[nxt[idx]] = prv[idx]; maxval = max(maxval, calcdist(prv[idx])); } int get(){ return maxval; } }; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); // cout.precision(20); int n, m; cin >> n >> m >> d; vector<int> y(n + m), nodeid(n + m); vector<vector<int>> hasx(d); for (int i = 0; i < n + m; i++){ int x; cin >> x >> y[i]; hasx[x].pb(i); } vector<pair<int, int>> sy(n + m); for (int i = 0; i < n + m; i++){ sy[i] = {y[i], i}; } sort(all(sy)); linkedlist startlist(sy); for (int i = 0; i < n + m; i++) nodeid[sy[i].se] = i; int ans = 1e9; for (int start = 0; start < d; start++){ linkedlist ls = startlist; int acnt = n; for (int finish = calc(start - 1);; finish = calc(finish - 1)){ if (acnt == 0){ ans = min(ans, (d - calc(finish - start) - 1) * (d + 1 - ls.get())); } for (auto i : hasx[finish]){ if (i < n) acnt--; else ls.del(nodeid[i]); } if (finish == start) break; } } cout << ans << endl; }
#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...