Submission #84486

# Submission time Handle Problem Language Result Execution time Memory
84486 2018-11-15T14:45:32 Z radoslav11 Circle selection (APIO18_circle_selection) C++14
100 / 100
2894 ms 433644 KB
/*
    https://codeforces.com/blog/entry/59650
*/

#include <bits/stdc++.h>
#define endl '\n'

#define SZ(x) ((int)x.size())
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound

using namespace std;
template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);

struct Circle
{
    int idx, rad, x, y;
    Circle() { idx = rad = x = y = 0; }
    Circle(int _i, int _r, int _x, int _y)
    {
        idx = _i;
        rad = _r;
        x = _x;
        y = _y;
    }
};

inline int64_t sq(int x) { return x * 1ll * x; }
bool cmp(const Circle &a, const Circle &b) { return a.rad != b.rad ? a.rad > b.rad : a.idx < b.idx; }
bool intersect(const Circle &a, const Circle &b) { return sq(a.x - b.x) + sq(a.y - b.y) <= sq(a.rad + b.rad); }

int n;
int answer[MAXN];
Circle a[MAXN];

void read()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i].x >> a[i].y >> a[i].rad;
        a[i].idx = i;
    }
}

map<pair<int, int>, vector<int> > M;

void rebuild(int block_size)
{
    M.clear();
    for(int i = 1; i <= n; i++)
        if(!answer[a[i].idx])
            M[{a[i].x / block_size, a[i].y / block_size}].push_back(i);
}

void solve()
{
    sort(a + 1, a + n + 1, cmp);

    int B = a[1].rad;
    rebuild(B);

    for(int i = 1; i <= n; i++)
    {
        if(answer[a[i].idx]) continue;

        while(a[i].rad * 2 <= B)
        {
            B >>= 1;
            rebuild(B);
        }

        answer[a[i].idx] = a[i].idx;

        int x = a[i].x / B, y = a[i].y / B;
        for(int dx = -2; dx <= 2; dx++)
            for(int dy = -2; dy <= 2; dy++)
            {
                int nx = dx + x;
                int ny = dy + y;

                if(M.count({nx, ny}))
                    for(int j: M[{nx, ny}])
                        if(!answer[a[j].idx] && intersect(a[i], a[j]))
                            answer[a[j].idx] = a[i].idx;
            }
    }

    for(int i = 1; i <= n; i++)
        cout << answer[i] << " ";
    cout << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    read();
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 16760 KB Output is correct
2 Correct 16 ms 16884 KB Output is correct
3 Correct 17 ms 16884 KB Output is correct
4 Correct 16 ms 16884 KB Output is correct
5 Correct 16 ms 16884 KB Output is correct
6 Correct 15 ms 16884 KB Output is correct
7 Correct 16 ms 16960 KB Output is correct
8 Correct 16 ms 17036 KB Output is correct
9 Correct 17 ms 17036 KB Output is correct
10 Correct 16 ms 17036 KB Output is correct
11 Correct 16 ms 17036 KB Output is correct
12 Correct 16 ms 17036 KB Output is correct
13 Correct 16 ms 17036 KB Output is correct
14 Correct 16 ms 17096 KB Output is correct
15 Correct 16 ms 17096 KB Output is correct
16 Correct 17 ms 17096 KB Output is correct
17 Correct 17 ms 17096 KB Output is correct
18 Correct 16 ms 17268 KB Output is correct
19 Correct 19 ms 17684 KB Output is correct
20 Correct 19 ms 17684 KB Output is correct
21 Correct 19 ms 17812 KB Output is correct
22 Correct 30 ms 18480 KB Output is correct
23 Correct 32 ms 18644 KB Output is correct
24 Correct 31 ms 18776 KB Output is correct
25 Correct 29 ms 18804 KB Output is correct
26 Correct 30 ms 19060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 195 ms 21816 KB Output is correct
2 Correct 206 ms 22640 KB Output is correct
3 Correct 208 ms 29540 KB Output is correct
4 Correct 197 ms 35288 KB Output is correct
5 Correct 283 ms 40380 KB Output is correct
6 Correct 992 ms 60544 KB Output is correct
7 Correct 361 ms 60544 KB Output is correct
8 Correct 481 ms 60544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 60544 KB Output is correct
2 Correct 592 ms 62632 KB Output is correct
3 Correct 2449 ms 86528 KB Output is correct
4 Correct 2486 ms 86608 KB Output is correct
5 Correct 2324 ms 86608 KB Output is correct
6 Correct 816 ms 86608 KB Output is correct
7 Correct 347 ms 86608 KB Output is correct
8 Correct 63 ms 86608 KB Output is correct
9 Correct 2789 ms 86608 KB Output is correct
10 Correct 2137 ms 86608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2086 ms 86752 KB Output is correct
2 Correct 1452 ms 86804 KB Output is correct
3 Correct 704 ms 86804 KB Output is correct
4 Correct 1541 ms 94140 KB Output is correct
5 Correct 1479 ms 101812 KB Output is correct
6 Correct 393 ms 101812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 16760 KB Output is correct
2 Correct 16 ms 16884 KB Output is correct
3 Correct 17 ms 16884 KB Output is correct
4 Correct 16 ms 16884 KB Output is correct
5 Correct 16 ms 16884 KB Output is correct
6 Correct 15 ms 16884 KB Output is correct
7 Correct 16 ms 16960 KB Output is correct
8 Correct 16 ms 17036 KB Output is correct
9 Correct 17 ms 17036 KB Output is correct
10 Correct 16 ms 17036 KB Output is correct
11 Correct 16 ms 17036 KB Output is correct
12 Correct 16 ms 17036 KB Output is correct
13 Correct 16 ms 17036 KB Output is correct
14 Correct 16 ms 17096 KB Output is correct
15 Correct 16 ms 17096 KB Output is correct
16 Correct 17 ms 17096 KB Output is correct
17 Correct 17 ms 17096 KB Output is correct
18 Correct 16 ms 17268 KB Output is correct
19 Correct 19 ms 17684 KB Output is correct
20 Correct 19 ms 17684 KB Output is correct
21 Correct 19 ms 17812 KB Output is correct
22 Correct 30 ms 18480 KB Output is correct
23 Correct 32 ms 18644 KB Output is correct
24 Correct 31 ms 18776 KB Output is correct
25 Correct 29 ms 18804 KB Output is correct
26 Correct 30 ms 19060 KB Output is correct
27 Correct 22 ms 101812 KB Output is correct
28 Correct 22 ms 101812 KB Output is correct
29 Correct 22 ms 101812 KB Output is correct
30 Correct 53 ms 101812 KB Output is correct
31 Correct 48 ms 101812 KB Output is correct
32 Correct 47 ms 101812 KB Output is correct
33 Correct 91 ms 101812 KB Output is correct
34 Correct 80 ms 101812 KB Output is correct
35 Correct 91 ms 101812 KB Output is correct
36 Correct 549 ms 101812 KB Output is correct
37 Correct 551 ms 102184 KB Output is correct
38 Correct 589 ms 104868 KB Output is correct
39 Correct 649 ms 104868 KB Output is correct
40 Correct 621 ms 105656 KB Output is correct
41 Correct 615 ms 106476 KB Output is correct
42 Correct 413 ms 109760 KB Output is correct
43 Correct 391 ms 112152 KB Output is correct
44 Correct 395 ms 114816 KB Output is correct
45 Correct 409 ms 117256 KB Output is correct
46 Correct 409 ms 119928 KB Output is correct
47 Correct 406 ms 122728 KB Output is correct
48 Correct 417 ms 125280 KB Output is correct
49 Correct 408 ms 127832 KB Output is correct
50 Correct 396 ms 130500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 16760 KB Output is correct
2 Correct 16 ms 16884 KB Output is correct
3 Correct 17 ms 16884 KB Output is correct
4 Correct 16 ms 16884 KB Output is correct
5 Correct 16 ms 16884 KB Output is correct
6 Correct 15 ms 16884 KB Output is correct
7 Correct 16 ms 16960 KB Output is correct
8 Correct 16 ms 17036 KB Output is correct
9 Correct 17 ms 17036 KB Output is correct
10 Correct 16 ms 17036 KB Output is correct
11 Correct 16 ms 17036 KB Output is correct
12 Correct 16 ms 17036 KB Output is correct
13 Correct 16 ms 17036 KB Output is correct
14 Correct 16 ms 17096 KB Output is correct
15 Correct 16 ms 17096 KB Output is correct
16 Correct 17 ms 17096 KB Output is correct
17 Correct 17 ms 17096 KB Output is correct
18 Correct 16 ms 17268 KB Output is correct
19 Correct 19 ms 17684 KB Output is correct
20 Correct 19 ms 17684 KB Output is correct
21 Correct 19 ms 17812 KB Output is correct
22 Correct 30 ms 18480 KB Output is correct
23 Correct 32 ms 18644 KB Output is correct
24 Correct 31 ms 18776 KB Output is correct
25 Correct 29 ms 18804 KB Output is correct
26 Correct 30 ms 19060 KB Output is correct
27 Correct 195 ms 21816 KB Output is correct
28 Correct 206 ms 22640 KB Output is correct
29 Correct 208 ms 29540 KB Output is correct
30 Correct 197 ms 35288 KB Output is correct
31 Correct 283 ms 40380 KB Output is correct
32 Correct 992 ms 60544 KB Output is correct
33 Correct 361 ms 60544 KB Output is correct
34 Correct 481 ms 60544 KB Output is correct
35 Correct 17 ms 60544 KB Output is correct
36 Correct 592 ms 62632 KB Output is correct
37 Correct 2449 ms 86528 KB Output is correct
38 Correct 2486 ms 86608 KB Output is correct
39 Correct 2324 ms 86608 KB Output is correct
40 Correct 816 ms 86608 KB Output is correct
41 Correct 347 ms 86608 KB Output is correct
42 Correct 63 ms 86608 KB Output is correct
43 Correct 2789 ms 86608 KB Output is correct
44 Correct 2137 ms 86608 KB Output is correct
45 Correct 2086 ms 86752 KB Output is correct
46 Correct 1452 ms 86804 KB Output is correct
47 Correct 704 ms 86804 KB Output is correct
48 Correct 1541 ms 94140 KB Output is correct
49 Correct 1479 ms 101812 KB Output is correct
50 Correct 393 ms 101812 KB Output is correct
51 Correct 22 ms 101812 KB Output is correct
52 Correct 22 ms 101812 KB Output is correct
53 Correct 22 ms 101812 KB Output is correct
54 Correct 53 ms 101812 KB Output is correct
55 Correct 48 ms 101812 KB Output is correct
56 Correct 47 ms 101812 KB Output is correct
57 Correct 91 ms 101812 KB Output is correct
58 Correct 80 ms 101812 KB Output is correct
59 Correct 91 ms 101812 KB Output is correct
60 Correct 549 ms 101812 KB Output is correct
61 Correct 551 ms 102184 KB Output is correct
62 Correct 589 ms 104868 KB Output is correct
63 Correct 649 ms 104868 KB Output is correct
64 Correct 621 ms 105656 KB Output is correct
65 Correct 615 ms 106476 KB Output is correct
66 Correct 413 ms 109760 KB Output is correct
67 Correct 391 ms 112152 KB Output is correct
68 Correct 395 ms 114816 KB Output is correct
69 Correct 409 ms 117256 KB Output is correct
70 Correct 409 ms 119928 KB Output is correct
71 Correct 406 ms 122728 KB Output is correct
72 Correct 417 ms 125280 KB Output is correct
73 Correct 408 ms 127832 KB Output is correct
74 Correct 396 ms 130500 KB Output is correct
75 Correct 261 ms 131304 KB Output is correct
76 Correct 247 ms 139764 KB Output is correct
77 Correct 220 ms 149504 KB Output is correct
78 Correct 225 ms 158376 KB Output is correct
79 Correct 303 ms 165440 KB Output is correct
80 Correct 217 ms 174992 KB Output is correct
81 Correct 2439 ms 213460 KB Output is correct
82 Correct 2362 ms 221136 KB Output is correct
83 Correct 2328 ms 228552 KB Output is correct
84 Correct 2470 ms 236312 KB Output is correct
85 Correct 2347 ms 243676 KB Output is correct
86 Correct 2279 ms 251020 KB Output is correct
87 Correct 2761 ms 258768 KB Output is correct
88 Correct 2532 ms 258768 KB Output is correct
89 Correct 2431 ms 260840 KB Output is correct
90 Correct 2368 ms 263564 KB Output is correct
91 Correct 2496 ms 266892 KB Output is correct
92 Correct 2374 ms 270236 KB Output is correct
93 Correct 1762 ms 280384 KB Output is correct
94 Correct 1848 ms 286420 KB Output is correct
95 Correct 1709 ms 292976 KB Output is correct
96 Correct 1770 ms 299768 KB Output is correct
97 Correct 2894 ms 306748 KB Output is correct
98 Correct 1232 ms 306748 KB Output is correct
99 Correct 1785 ms 320176 KB Output is correct
100 Correct 1702 ms 326056 KB Output is correct
101 Correct 1733 ms 326372 KB Output is correct
102 Correct 1749 ms 338816 KB Output is correct
103 Correct 2458 ms 345296 KB Output is correct
104 Correct 1766 ms 352696 KB Output is correct
105 Correct 1509 ms 356352 KB Output is correct
106 Correct 1456 ms 361932 KB Output is correct
107 Correct 1371 ms 368744 KB Output is correct
108 Correct 1417 ms 375488 KB Output is correct
109 Correct 1354 ms 383108 KB Output is correct
110 Correct 1368 ms 389668 KB Output is correct
111 Correct 1337 ms 397272 KB Output is correct
112 Correct 1319 ms 403952 KB Output is correct
113 Correct 1390 ms 410604 KB Output is correct
114 Correct 1445 ms 418088 KB Output is correct
115 Correct 1416 ms 425864 KB Output is correct
116 Correct 1376 ms 433644 KB Output is correct