Submission #59928

#TimeUsernameProblemLanguageResultExecution timeMemory
59928Eae02Circle selection (APIO18_circle_selection)C++14
19 / 100
3066 ms37644 KiB
#include <bits/stdc++.h> #define ALL(x) x.begin(),x.end() struct Circle { int64_t x; int64_t y; int64_t r; int64_t i; int64_t elimBy; int64_t minX() const { return x - r; } int64_t maxX() const { return x + r; } }; int main() { int num; std::cin >> num; std::vector<Circle> circles(num); std::vector<Circle*> cByMin(num); std::vector<Circle*> cByMax(num); bool allZeroY = true; for (int i = 0; i < num; i++) { std::cin >> circles[i].x; std::cin >> circles[i].y; std::cin >> circles[i].r; circles[i].i = i; circles[i].elimBy = -1; cByMin[i] = &circles[i]; cByMax[i] = &circles[i]; if (circles[i].y != 0) allZeroY = false; } std::sort(ALL(circles), [&] (const Circle& a, const Circle& b) { if (a.r == b.r) return a.i < b.i; return a.r > b.r; }); if (allZeroY) { std::sort(ALL(cByMin), [&] (const Circle* a, const Circle* b) { return a->minX() < b->minX(); }); std::sort(ALL(cByMax), [&] (const Circle* a, const Circle* b) { return a->maxX() < b->maxX(); }); for (Circle& outer : circles) { if (outer.elimBy != -1) continue; outer.elimBy = outer.i; auto minB = std::lower_bound(ALL(cByMin), outer.minX(), [&] (Circle* c, int64_t pos) { return c->minX() < pos; }); auto minE = std::upper_bound(ALL(cByMin), outer.maxX(), [&] (int64_t pos, Circle* c) { return pos < c->minX(); }); auto maxB = std::lower_bound(ALL(cByMax), outer.minX(), [&] (Circle* c, int64_t pos) { return c->maxX() < pos; }); auto maxE = std::upper_bound(ALL(cByMax), outer.maxX(), [&] (int64_t pos, Circle* c) { return pos <= c->maxX(); }); std::for_each(minB, minE, [&] (Circle* c) { if (c->elimBy == -1) c->elimBy = outer.i; }); std::for_each(maxB, maxE, [&] (Circle* c) { if (c->elimBy == -1) c->elimBy = outer.i; }); } } else { for (Circle& outer : circles) { if (outer.elimBy != -1) continue; outer.elimBy = outer.i; for (Circle& inner : circles) { if (inner.elimBy != -1) continue; int64_t dx = inner.x - outer.x; int64_t dy = inner.y - outer.y; int64_t rSum = inner.r + outer.r; if (dx * dx + dy * dy <= rSum * rSum) inner.elimBy = outer.i; } } } std::vector<int64_t> result(num); for (int i = 0; i < num; i++) result[circles[i].i] = circles[i].elimBy + 1; for (int i = 0; i < num; i++) std::cout << result[i] << " "; std::cout << std::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...