Submission #258777

#TimeUsernameProblemLanguageResultExecution timeMemory
258777SaboonHamburg Steak (JOI20_hamburg)C++14
15 / 100
148 ms4256 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 2e5 + 10; const int inf = 1e9 + 1; multiset<int> Ls, Ds, Rs, Us; int L[maxn], R[maxn], D[maxn], U[maxn]; int mark[maxn]; pair<int,int> ans[5]; bool check(int,int,int,int); bool solve(int n, int k){ if (k == 1){ bool cor = 1; int x = inf-1, y = inf-1; for (int i = 1; i <= n; i++) if (!mark[i]) x = min(x, R[i]), y = min(y, U[i]); for (int i = 1; i <= n; i++) if (!mark[i]) cor &= (L[i] <= x and x <= R[i] and D[i] <= y and y <= U[i]); if (cor) ans[k] = {x,y}; return cor; } if (k == 2){ int x = inf-1, y1 = inf-1, y2 = 1; for (int i = 1; i <= n; i++) if (!mark[i]) x = min(x, R[i]), y1 = min(y1, U[i]), y2 = max(y2, D[i]); bool ret = check(n, k, x, y1); if (ret == true) return true; ret = check(n, k, x, y2); return ret; } if (k == 3){ int x1 = inf-1, x2 = 1, y1 = inf-1, y2 = 1; for (int i = 1; i <= n; i++) if (!mark[i]) x1 = min(x1, R[i]), x2 = max(x2, L[i]), y1 = min(y1, U[i]), y2 = max(y2, D[i]); bool ret = check(n, k, x1, y1); if (ret == true) return true; ret = check(n, k, x1, y2); if (ret == true) return true; ret = check(n, k, x2, y1); if (ret == true) return true; ret = check(n, k, x2, y2); return ret; } if (k == 4){ int x = inf-1; for (int i = 1; i <= n; i++) x = min(x, R[i]); vector<pair<int,int>> seg; for (int i = 1; i <= n; i++) if (L[i] <= x) seg.push_back({D[i],i}); sort(seg.rbegin(), seg.rend()); int minl = inf; for (auto it : seg){ int idx = it.second; if (U[idx] < minl){ check(n, k, x, D[idx]); minl = U[idx]; } } } return false; } bool check(int n, int k, int x, int y){ for (int i = 1; i <= n; i++) if (!mark[i] and L[i] <= x and x <= R[i] and D[i] <= y and y <= U[i]) mark[i] = k; ans[k] = {x,y}; bool ret = solve(n, k-1); if (ret == true) return true; for (int i = 1; i <= n; i++) if (mark[i] == k) mark[i] = 0; return false; } int main(){ ios_base::sync_with_stdio(false); int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> L[i] >> D[i] >> R[i] >> U[i]; bool solved = solve(n, k); assert(solved); for (int i = 1; i <= k; i++) cout << ans[i].first << " " << ans[i].second << 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...