제출 #833967

#제출 시각아이디문제언어결과실행 시간메모리
833967sysiaGarden (JOI23_garden)C++17
14 / 100
1527 ms18928 KiB
//Sylwia Sapkowska #include <bits/stdc++.h> #pragma GCC optimize("O3", "unroll-loops") using namespace std; void __print(int x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << "'" << x << "'";} void __print(const char *x) {cerr << '"' << x << '"';} void __print(const string &x) {cerr << '"' << x << '"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifdef LOCAL #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif #define int long long typedef pair<int, int> T; const int oo = 1e18, oo2 = 1e9+7, K = 30; const int mod = 998244353; void solve(){ int n, m, d; cin >> n >> m >> d; vector<int>X, Y; int mx = 2*d; vector<vector<int>>pion(mx), poz(mx), p(mx); for (int i = 0; i<n; i++){ int x, y; cin >> x >> y; //4 punkty p[x].emplace_back(y); p[x+d].emplace_back(y); } vector<int>tab(d); //tylko punkty int sum = 0; vector<int>last(d, -1), cnt(d); //punkty z prostych poziomych for (int i = 0; i<m; i++){ int a, b; cin >> a >> b; X.emplace_back(a); Y.emplace_back(b); cnt[b]++; last[b] = max(last[b],a); pion[a].emplace_back(i); pion[a+d].emplace_back(i); poz[b].emplace_back(i); } int ans = oo; auto add = [&](int R){ for (auto y: p[R]) { tab[y]++; sum++; } for (auto i:pion[R]){ cnt[Y[i]]--; if (!cnt[Y[i]]) last[Y[i]] = -1; } }; auto remove = [&](int L){ for (auto y: p[L]){ tab[y]--; sum--; } for (auto i: pion[L]){ cnt[Y[i]]++; last[Y[i]] = L+d; } }; auto calc = [&](int L, int R, vector<int>a){ for (int i = 0; i < d;i++) a[i] += cnt[i]; int S = accumulate(a.begin(), a.end(), 0); for (int i = 0; i<d; i++) a.emplace_back(a[i]); // debug(a); vector<T>ord; for (int i = 0; i<d; i++){ if (last[i] > R && !tab[i]){ ord.emplace_back(last[i], i); } } // debug(ord); sort(ord.begin(), ord.end()); for (int rep = 0; rep < 2; rep++){ set<int>pos; for (int i = 0; i<mx; i++) if (a[i]) pos.insert(i); int r = -1; int curr = 0; set<T>beg; int mn = oo; for (int l = 0; l < d; l++){ while (curr < S){ curr += a[++r]; } if (curr == S && a[l] > 0){ beg.insert({l, r}); ans = min(ans, (R-L+1)*(r-l+1)); mn = min(mn, r-l+1); } curr -= a[l]; } // debug(beg); //i teraz bedziemy ustawiac 0 na niektorych pozycjach for (auto [R2, i]: ord){ //i, i+d = 0 for (auto l: vector<int>{i, i+d}){ auto it = beg.lower_bound({l, -oo}); if (it == beg.end() || it->first != l) continue; auto it2 = next(pos.lower_bound(l)); if (it2 == pos.end()) continue; int rr = it->second; int ll = *it2; beg.erase(it); if (rr >= ll){ mn = min(mn, rr-ll+1); beg.insert({ll, rr}); } pos.erase(i); } ans = min(ans, (R2-L+1)*mn); } reverse(a.begin(), a.end()); for (auto &[x, i]: ord) i = d-i-1; } }; int R = -1; tab.assign(d, 0); for (int L = 0; L < d; L++){ while (R+1 < 2*d && sum != n){ add(++R); } if (sum == n){ // debug(L, R); // debug(last); // debug(tab); // debug(cnt); calc(L, R, tab); } remove(L); } cout << ans << "\n"; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 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...