Submission #831852

#TimeUsernameProblemLanguageResultExecution timeMemory
831852WLZGarden (JOI23_garden)C++17
45 / 100
3054 ms11508 KiB
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, d; cin >> n >> m >> d; vector<int> p(n), q(n), r(m), s(m); for (int i = 0; i < n; i++) cin >> p[i] >> q[i]; for (int i = 0; i < m; i++) cin >> r[i] >> s[i]; vector<bool> type_1(d, false); for (int i = 0; i < n; i++) type_1[q[i]] = true; vector<int> last(d, -1); for (int i = 0; i < m; i++) if (!type_1[s[i]]) last[s[i]] = max(last[s[i]], r[i]); vector< set<int> > type_2(d, set<int>()); for (int i = 0; i < d; i++) if (last[i] != -1) type_2[last[i]].insert(i); vector< vector<int> > by_r(d); for (int i = 0; i < m; i++) by_r[r[i]].push_back(s[i]); set<int> all; vector<int> v, cnt(d, 0); for (int i = 0; i < n; i++) all.insert(q[i]), v.push_back(q[i]), cnt[p[i]]++; for (int i = 0; i < m; i++) all.insert(s[i]), v.push_back(s[i]); sort(v.begin(), v.end()); int ans = INF, mx_b = -INF; for (int i = 1; i < (int) v.size(); i++) mx_b = max(mx_b, v[i] - v[i - 1]); if ((int) v.size() >= 2) mx_b = max(mx_b, v[0] - v.back() + d); for (int l = 0; l < d; l++) { int mx = mx_b, cnt_1 = 0; set<int> st = all; for (int r = l; r < l + d; r++) { int tmp_r = r; r %= d; cnt_1 += cnt[r]; for (auto &x : type_2[r]) { auto it = st.find(x); if ((int) st.size() > 2) { set<int>::iterator prv, nxt = next(it); if (it == st.begin()) prv = prev(st.end()); else prv = prev(it); if (nxt == st.end()) nxt = st.begin(); mx = max(mx, (*nxt - *prv + d) % d); } st.erase(x); if ((int) st.size() <= 1) mx = d; } r = tmp_r; if (cnt_1 == n) ans = min(ans, (r - l + 1) * (d - mx + 1)); } for (auto &x : by_r[l]) { if (type_1[x]) continue; type_2[last[x] % d].erase(x); last[x] = l + d; type_2[last[x] % d].insert(x); } } cout << ans << '\n'; 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...