제출 #1160998

#제출 시각아이디문제언어결과실행 시간메모리
1160998not_amir원 고르기 (APIO18_circle_selection)C++20
100 / 100
431 ms22336 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct circle { ll x, y, r; }; bool intersect(circle a, circle b) { return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) <= (a.r + b.r) * (a.r + b.r); } constexpr int B = 700; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n; cin >> n; vector<circle> c(n); for (int i = 0; i < n; i++) cin >> c[i].x >> c[i].y >> c[i].r; vector<array<ll, 3>> cmp; vector ans(n, - 1); ll r = LONG_MAX; auto compress = [&](ll nr) { r = 2 * nr; cmp.clear(); for (int i = 0; i < n; i++) if (ans[i] == -1) cmp.push_back({c[i].x / r, c[i].y / r, i}); sort(cmp.begin(), cmp.end()); }; vector<int> ord(n); iota(ord.begin(), ord.end(), 0); sort(ord.begin(), ord.end(), [&](int a, int b) { if (c[a].r == c[b].r) return a < b; return c[a].r > c[b].r; }); for (int i : ord) { if (ans[i] >= 0) continue; if (4 * c[i].r < r) compress(c[i].r); ans[i] = i; ll cx = c[i].x / r, cy = c[i].y / r; for (int x = cx - 1; x <= cx + 1; x++) { auto it = lower_bound(cmp.begin(), cmp.end(), array<ll, 3>({x, cy - 1, -1})); while (it != cmp.end() && (*it)[0] == x && (*it)[1] <= cy + 1) { if (ans[(*it)[2]] == -1 && intersect(c[(*it)[2]], c[i])) ans[(*it)[2]] = i; it++; } } } for (int i = 0; i < n; i++) cout << ans[i] + 1 << " "; } /* 3 0 0 3 1 2 3 2 2 3 */
#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...