Submission #831782

#TimeUsernameProblemLanguageResultExecution timeMemory
831782WLZGarden (JOI23_garden)C++17
30 / 100
3078 ms55424 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); vector<int> cnt_a(d, 0); for (int i = 0; i < n; i++) cin >> p[i] >> q[i], cnt_a[p[i]]++; vector< vector<int> > s2(d, vector<int>()); for (int i = 0; i < m; i++) cin >> r[i] >> s[i], s2[r[i]].push_back(s[i]); int ans = INF; for (int x1 = 0; x1 < d; x1++) { int cnt_1 = 0; multiset<int> st, st_diff; for (int i = 0; i < n; i++) st.insert(q[i]); for (int i = 0; i < m; i++) st.insert(s[i]); for (auto it = next(st.begin()); it != st.end(); it++) st_diff.insert(*it - *prev(it)); if ((int) st.size() >= 2) st_diff.insert(*st.begin() + d - *st.rbegin()); for (int x2 = x1; x2 < x1 + d; x2++) { cnt_1 += cnt_a[x2 % d]; for (auto &s : s2[x2 % d]) { auto it = st.find(s); if ((int) st.size() > 2) { auto prv = prev(it), nxt = next(it); if (it == st.begin()) prv = prev(st.end()); if (nxt == st.end()) nxt = st.begin(); st_diff.erase(st_diff.find(((*it - *prv) % d + d) % d)); st_diff.erase(st_diff.find(((*nxt - *it) % d + d) % d)); st_diff.insert(((*nxt - *prv) % d + d) % d); st.erase(it); } } if (cnt_1 < n) continue; if ((int) st.size() < 2) ans = min(ans, x2 - x1 + 1); else ans = min(ans, (x2 - x1 + 1) * (d - *st_diff.rbegin() + 1)); } } 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...