# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
372815 | 2021-03-01T20:53:35 Z | luciocf | 원 고르기 (APIO18_circle_selection) | C++14 | 1121 ms | 19840 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 3e5+10; struct Circle { int x, y, r, ind; bool operator<(const ll &o) const { return 1ll*y < o; } } circle[maxn]; vector<vector<Circle>> V; int R; int ans[maxn]; bool comp1(Circle a, Circle b) { if (a.x < b.x) return a.y < b.y; return a.x < b.x; } bool comp2(Circle a, Circle b) { if (a.r == b.r) return a.ind < b.ind; return a.r > b.r; } bool intersect(Circle a, Circle b) { long double dx = a.x-b.x, dy = a.y-b.y, dr = a.r+b.r; return dx*dx + dy*dy <= dr*dr; } void doit(int pos, int c) { int x = circle[c].x, y = circle[c].y; int sign = (y < 0 ? 1 : -1); ll l_y = 1ll*y + 1ll*sign*(y%R) - 2ll*R, r_y = 1ll*y + 1ll*sign*(y%R) + 3ll*R; auto it = lower_bound(V[pos].begin(), V[pos].end(), l_y); for (; it != V[pos].end() && it->y <= 1ll*r_y; it++) if (intersect(circle[c], *it)) ans[it->ind] = circle[c].ind; } int main(void) { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d %d %d", &circle[i].x, &circle[i].y, &circle[i].r); circle[i].ind = i; } R = circle[1].r; sort(circle+1, circle+n+1, comp1); for (int i = 1; i <= n; i++) { if (i == 1 || circle[i].x > circle[i-1].x) V.push_back(vector<Circle>()); V.back().push_back(circle[i]); } sort(circle+1, circle+n+1, comp2); for (int i = 1; i <= n; i++) { if (ans[circle[i].ind]) continue; int x = circle[i].x, y = circle[i].y; int sign = (x < 0 ? 1 : -1); ll l_x = 1ll*x + 1ll*sign*(x%R) - 2ll*R, r_x = 1ll*x + 1ll*sign*(x%R) + 3ll*R; int p_l, p_r; int ini = 0, fim = (int)V.size()-1; while (ini <= fim) { int mid = (ini+fim)>>1; if (1ll*V[mid][0].x >= l_x) p_l = mid, fim = mid-1; else ini = mid+1; } ini = 0, fim = (int)V.size()-1; while (ini <= fim) { int mid = (ini+fim)>>1; if (1ll*V[mid][0].x <= r_x) p_r = mid, ini = mid+1; else fim = mid-1; } for (int j = p_l; j <= p_r; j++) doit(j, i); } for (int i = 1; i <= n; i++) printf("%d ", ans[i]); printf("\n"); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Incorrect | 1 ms | 364 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 243 ms | 19840 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 364 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1121 ms | 19036 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Incorrect | 1 ms | 364 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Incorrect | 1 ms | 364 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |