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

#TimeUsernameProblemLanguageResultExecution timeMemory
834049sysiaGarden (JOI23_garden)C++17
100 / 100
2387 ms27916 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>Y; //,X; 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){ // if (L != 3) return; int S = 0; for (int i = 0; i < d; i++) { a[i] += cnt[i]; S += a[i]; } for (int i = 0; i<d; i++) a.emplace_back(a[i]); vector<int>prev(mx, oo), nxt(mx, oo); for (int i = 1; i<mx; i++){ prev[i] = (a[i-1] ? i-1 : prev[i-1]); } for (int i = mx-2; i>=0; i--){ nxt[i] = (a[i+1] ? i+1 : nxt[i+1]); } debug(a); vector<T>ord; for (int i = 0; i<d; i++){ if (last[i] > R && !tab[i]){ ord.emplace_back(last[i], i); } } sort(ord.begin(), ord.end()); debug(ord); int r = -1; int curr = 0; vector<int>pocz(mx, -1), kon(mx, -1); int mn = oo; for (int l = 0; l < d; l++){ while (curr < S){ curr += a[++r]; } if (curr == S){ pocz[l] = r; kon[r] = max(kon[r], l); ans = min(ans, (R-L+1)*(r-l+1)); mn = min(mn, r-l+1); } curr -= a[l]; } debug(pocz); debug(kon); //i teraz bedziemy ustawiac 0 na niektorych pozycjach for (auto [R2, i]: ord){ for (auto p: {i, i+d}){ //1. przedzial zaczynajacy sie w p int newl = nxt[p]; if (pocz[p] != -1 && newl != oo) { //nowy przedzial(!) debug(p, pocz[p], newl); pocz[newl] = pocz[p]; kon[pocz[p]] = newl; mn = min(mn, pocz[p]-newl+1); } //2. przedzial konczacy sie w p int newr = prev[p]; if (kon[p] != -1 && newr != oo){ kon[newr] = max(kon[newr], kon[p]); pocz[kon[p]] = newr; mn = min(mn, newr-kon[p]+1); } if (prev[p] != oo) nxt[prev[p]] = nxt[p]; if (nxt[p] != oo) prev[nxt[p]] = prev[p]; } debug(R2-L+1, mn); ans = min(ans, (R2-L+1)*mn); } }; 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...