Submission #1087261

#TimeUsernameProblemLanguageResultExecution timeMemory
1087261TrungNotChungCircle selection (APIO18_circle_selection)C++17
100 / 100
1392 ms49236 KiB
#include <bits/stdc++.h> #define pii pair<int, int> #define fi first #define se second #define task "main" using namespace std; const int N = (int)3e5 + 10; struct Circle { int x, y, r, i; Circle(int _x = 0, int _y = 0, int _r = 0, int _i = 0) { x = _x, y = _y, r = _r, i = _i; } } circles[N]; int n; int res[N]; bool cmp(const Circle &a, const Circle &b){ if (a.r == b.r) return a.i < b.i; return a.r > b.r; } bool intersect(const Circle &a, const Circle &b) { return 1LL * (a.x - b.x) * (a.x - b.x) + 1LL * (a.y - b.y) * (a.y - b.y) <= 1LL * (a.r + b.r) * (a.r + b.r); } void solve() { cin >> n; for(int i = 0; i < n; i++) { cin >> circles[i].x >> circles[i].y >> circles[i].r; circles[i].i = i; } sort (circles, circles + n, cmp); memset(res, -1, sizeof res); for (int lg = 30; lg >= 0; --lg) { int r = (1 << lg); map<pii, vector<int> > grid; bool found = false; for (int i = 0; i < n; ++i) { if (res[circles[i].i] == -1 && circles[i].r >= r / 2 && circles[i].r <= r) { found = true; break; } } if(!found) continue; for (int i = 0; i < n; ++i) { if (res[circles[i].i] == -1) { grid[pii(circles[i].x / r, circles[i].y / r)].push_back(i); } } for (int i = 0; i < n; ++i) { if (circles[i].r < r / 2) break; if (res[circles[i].i] != -1 || circles[i].r > r) continue; for(int x = circles[i].x / r - 2; x <= circles[i].x / r + 2; ++x) { for(int y = circles[i].y / r - 2; y <= circles[i].y / r + 2; ++y) { if (grid.find(pii(x, y)) == grid.end()) continue; vector<int> &candidates = grid[pii(x, y)]; for (int j = (int)candidates.size() - 1; j >= 0; --j) { int c = candidates[j]; if (res[circles[c].i] == -1 && intersect(circles[c], circles[i])) { res[circles[c].i] = circles[i].i; swap (candidates[j], candidates.back()); candidates.pop_back(); } } } } } } for(int i = 0; i < n; i++) cout << res[i] + 1 << ' '; } int main() { #ifdef LOCAL freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 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...