Submission #811244

# Submission time Handle Problem Language Result Execution time Memory
811244 2023-08-07T03:04:40 Z CYMario Circle selection (APIO18_circle_selection) C++17
100 / 100
625 ms 47268 KB
#include <stdio.h>
#include <algorithm>
#include <list>
#include <unordered_map>
#define getchar getchar_unlocked
#define putchar putchar_unlocked
using namespace std;
typedef long long i64;
int rd()
{
    int k = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9')
    {
        if (c == '-')
            f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
    {
        k = (k << 1) + (k << 3) + (c ^ 48);
        c = getchar();
    }
    return f == 1 ? k : -k;
}
void wr(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        wr(x / 10);
    putchar((x % 10) ^ '0');
}
const int maxn = 300010, INF = 1000000000;
struct point
{
    int x, y;
    point(int _x = 0, int _y = 0) : x(_x), y(_y) {}
    bool operator< (const point& o) const { return (x ^ o.x) ? x < o.x : y < o.y; }
    bool operator==(const point& o) const { return (x == o.x) && (y == o.y); }
};
struct point_hash
{
    size_t operator()(const point &a) const { return hash<int>()(a.x) * 611953 + hash<int>()(a.y) * 7919; }
};
struct circle
{
    point c;
    int r;
} c[maxn];
int n, idx[maxn], ans[maxn];
bool cmp(int a, int b) 
{
    if (c[a].r ^ c[b].r)
        return c[a].r > c[b].r;
    else
        return a < b;
}
// map<point, list<int>> mp;
unordered_map<point, list<int>, point_hash> mp;
int grid_r;
void build(int r)
{
    grid_r = r;
    mp.clear();
    for (int i = 1; i <= n; ++i)
        if (!ans[i])
            mp[point((c[i].c.x + INF) / grid_r, (c[i].c.y + INF) / grid_r)].push_back(i);
}
bool check(int i, int j)
{
    i64 dis = 1ll * (c[i].c.x - c[j].c.x) * (c[i].c.x - c[j].c.x) + 1ll * (c[i].c.y - c[j].c.y) * (c[i].c.y - c[j].c.y);
    return dis <= 1ll * (c[i].r + c[j].r) * (c[i].r + c[j].r);
}
int main()
{
    n = rd();
    for (int i = 1; i <= n; ++i)
        c[i].c.x = rd(), c[i].c.y = rd(), c[i].r = rd();
    for (int i = 1; i <= n; ++i)
        idx[i] = i;
    sort(idx + 1, idx + n + 1, cmp);
    build(c[idx[1]].r << 1);
    for (int i = 1; i <= n; ++i)
    {
        if (ans[idx[i]])
            continue;
        if ((i64)grid_r > ((i64)(c[idx[i]].r) << 2))
            build(c[idx[i]].r << 1);
        int x = (c[idx[i]].c.x + INF) / grid_r, y = (c[idx[i]].c.y + INF) / grid_r;
        for (int dx = -1; dx <= 1; ++dx)
            for (int dy = -1; dy <= 1; ++dy)
            {
                point pt = point(x + dx, y + dy);
                if (!mp.count(pt))
                    continue;
                list<int>& it = mp[pt];
                for (list<int>::iterator itt = it.begin(); itt != it.end(); )
                {
                    if (check(idx[i], *itt))
                        ans[*itt] = idx[i], it.erase(itt++);
                    else
                        ++itt;
                }
            }
    }
    for (int i = 1; i <= n; ++i)
        wr(ans[i]), putchar(' ');
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3924 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3796 KB Output is correct
6 Correct 2 ms 3820 KB Output is correct
7 Correct 2 ms 3928 KB Output is correct
8 Correct 2 ms 3796 KB Output is correct
9 Correct 2 ms 3796 KB Output is correct
10 Correct 2 ms 3820 KB Output is correct
11 Correct 2 ms 3796 KB Output is correct
12 Correct 2 ms 3812 KB Output is correct
13 Correct 2 ms 3796 KB Output is correct
14 Correct 2 ms 3796 KB Output is correct
15 Correct 2 ms 3796 KB Output is correct
16 Correct 2 ms 3832 KB Output is correct
17 Correct 2 ms 3796 KB Output is correct
18 Correct 2 ms 3848 KB Output is correct
19 Correct 3 ms 4088 KB Output is correct
20 Correct 3 ms 4180 KB Output is correct
21 Correct 3 ms 4180 KB Output is correct
22 Correct 5 ms 4476 KB Output is correct
23 Correct 5 ms 4476 KB Output is correct
24 Correct 7 ms 4440 KB Output is correct
25 Correct 5 ms 4436 KB Output is correct
26 Correct 5 ms 4476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 24392 KB Output is correct
2 Correct 93 ms 24264 KB Output is correct
3 Correct 93 ms 24044 KB Output is correct
4 Correct 91 ms 24404 KB Output is correct
5 Correct 115 ms 22224 KB Output is correct
6 Correct 217 ms 28992 KB Output is correct
7 Correct 132 ms 22860 KB Output is correct
8 Correct 141 ms 23832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3796 KB Output is correct
2 Correct 97 ms 18608 KB Output is correct
3 Correct 576 ms 47092 KB Output is correct
4 Correct 583 ms 47100 KB Output is correct
5 Correct 499 ms 40636 KB Output is correct
6 Correct 148 ms 22592 KB Output is correct
7 Correct 57 ms 13680 KB Output is correct
8 Correct 10 ms 5844 KB Output is correct
9 Correct 625 ms 45948 KB Output is correct
10 Correct 458 ms 40040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 424 ms 46960 KB Output is correct
2 Correct 423 ms 46060 KB Output is correct
3 Correct 126 ms 27308 KB Output is correct
4 Correct 419 ms 46460 KB Output is correct
5 Correct 413 ms 46704 KB Output is correct
6 Correct 107 ms 25932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3924 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3796 KB Output is correct
6 Correct 2 ms 3820 KB Output is correct
7 Correct 2 ms 3928 KB Output is correct
8 Correct 2 ms 3796 KB Output is correct
9 Correct 2 ms 3796 KB Output is correct
10 Correct 2 ms 3820 KB Output is correct
11 Correct 2 ms 3796 KB Output is correct
12 Correct 2 ms 3812 KB Output is correct
13 Correct 2 ms 3796 KB Output is correct
14 Correct 2 ms 3796 KB Output is correct
15 Correct 2 ms 3796 KB Output is correct
16 Correct 2 ms 3832 KB Output is correct
17 Correct 2 ms 3796 KB Output is correct
18 Correct 2 ms 3848 KB Output is correct
19 Correct 3 ms 4088 KB Output is correct
20 Correct 3 ms 4180 KB Output is correct
21 Correct 3 ms 4180 KB Output is correct
22 Correct 5 ms 4476 KB Output is correct
23 Correct 5 ms 4476 KB Output is correct
24 Correct 7 ms 4440 KB Output is correct
25 Correct 5 ms 4436 KB Output is correct
26 Correct 5 ms 4476 KB Output is correct
27 Correct 4 ms 4564 KB Output is correct
28 Correct 4 ms 4476 KB Output is correct
29 Correct 4 ms 4476 KB Output is correct
30 Correct 9 ms 5120 KB Output is correct
31 Correct 9 ms 5104 KB Output is correct
32 Correct 9 ms 5236 KB Output is correct
33 Correct 30 ms 11340 KB Output is correct
34 Correct 31 ms 11392 KB Output is correct
35 Correct 36 ms 11220 KB Output is correct
36 Correct 89 ms 18380 KB Output is correct
37 Correct 93 ms 18488 KB Output is correct
38 Correct 89 ms 18512 KB Output is correct
39 Correct 135 ms 13544 KB Output is correct
40 Correct 140 ms 13544 KB Output is correct
41 Correct 140 ms 13560 KB Output is correct
42 Correct 39 ms 11796 KB Output is correct
43 Correct 66 ms 18236 KB Output is correct
44 Correct 67 ms 18244 KB Output is correct
45 Correct 61 ms 18176 KB Output is correct
46 Correct 110 ms 18248 KB Output is correct
47 Correct 66 ms 18180 KB Output is correct
48 Correct 73 ms 18192 KB Output is correct
49 Correct 67 ms 18240 KB Output is correct
50 Correct 64 ms 18180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3924 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3796 KB Output is correct
6 Correct 2 ms 3820 KB Output is correct
7 Correct 2 ms 3928 KB Output is correct
8 Correct 2 ms 3796 KB Output is correct
9 Correct 2 ms 3796 KB Output is correct
10 Correct 2 ms 3820 KB Output is correct
11 Correct 2 ms 3796 KB Output is correct
12 Correct 2 ms 3812 KB Output is correct
13 Correct 2 ms 3796 KB Output is correct
14 Correct 2 ms 3796 KB Output is correct
15 Correct 2 ms 3796 KB Output is correct
16 Correct 2 ms 3832 KB Output is correct
17 Correct 2 ms 3796 KB Output is correct
18 Correct 2 ms 3848 KB Output is correct
19 Correct 3 ms 4088 KB Output is correct
20 Correct 3 ms 4180 KB Output is correct
21 Correct 3 ms 4180 KB Output is correct
22 Correct 5 ms 4476 KB Output is correct
23 Correct 5 ms 4476 KB Output is correct
24 Correct 7 ms 4440 KB Output is correct
25 Correct 5 ms 4436 KB Output is correct
26 Correct 5 ms 4476 KB Output is correct
27 Correct 93 ms 24392 KB Output is correct
28 Correct 93 ms 24264 KB Output is correct
29 Correct 93 ms 24044 KB Output is correct
30 Correct 91 ms 24404 KB Output is correct
31 Correct 115 ms 22224 KB Output is correct
32 Correct 217 ms 28992 KB Output is correct
33 Correct 132 ms 22860 KB Output is correct
34 Correct 141 ms 23832 KB Output is correct
35 Correct 1 ms 3796 KB Output is correct
36 Correct 97 ms 18608 KB Output is correct
37 Correct 576 ms 47092 KB Output is correct
38 Correct 583 ms 47100 KB Output is correct
39 Correct 499 ms 40636 KB Output is correct
40 Correct 148 ms 22592 KB Output is correct
41 Correct 57 ms 13680 KB Output is correct
42 Correct 10 ms 5844 KB Output is correct
43 Correct 625 ms 45948 KB Output is correct
44 Correct 458 ms 40040 KB Output is correct
45 Correct 424 ms 46960 KB Output is correct
46 Correct 423 ms 46060 KB Output is correct
47 Correct 126 ms 27308 KB Output is correct
48 Correct 419 ms 46460 KB Output is correct
49 Correct 413 ms 46704 KB Output is correct
50 Correct 107 ms 25932 KB Output is correct
51 Correct 4 ms 4564 KB Output is correct
52 Correct 4 ms 4476 KB Output is correct
53 Correct 4 ms 4476 KB Output is correct
54 Correct 9 ms 5120 KB Output is correct
55 Correct 9 ms 5104 KB Output is correct
56 Correct 9 ms 5236 KB Output is correct
57 Correct 30 ms 11340 KB Output is correct
58 Correct 31 ms 11392 KB Output is correct
59 Correct 36 ms 11220 KB Output is correct
60 Correct 89 ms 18380 KB Output is correct
61 Correct 93 ms 18488 KB Output is correct
62 Correct 89 ms 18512 KB Output is correct
63 Correct 135 ms 13544 KB Output is correct
64 Correct 140 ms 13544 KB Output is correct
65 Correct 140 ms 13560 KB Output is correct
66 Correct 39 ms 11796 KB Output is correct
67 Correct 66 ms 18236 KB Output is correct
68 Correct 67 ms 18244 KB Output is correct
69 Correct 61 ms 18176 KB Output is correct
70 Correct 110 ms 18248 KB Output is correct
71 Correct 66 ms 18180 KB Output is correct
72 Correct 73 ms 18192 KB Output is correct
73 Correct 67 ms 18240 KB Output is correct
74 Correct 64 ms 18180 KB Output is correct
75 Correct 97 ms 26572 KB Output is correct
76 Correct 97 ms 26348 KB Output is correct
77 Correct 95 ms 26532 KB Output is correct
78 Correct 90 ms 26332 KB Output is correct
79 Correct 127 ms 26228 KB Output is correct
80 Correct 92 ms 26352 KB Output is correct
81 Correct 560 ms 47108 KB Output is correct
82 Correct 564 ms 46876 KB Output is correct
83 Correct 565 ms 46820 KB Output is correct
84 Correct 587 ms 47268 KB Output is correct
85 Correct 555 ms 46900 KB Output is correct
86 Correct 564 ms 46972 KB Output is correct
87 Correct 543 ms 46604 KB Output is correct
88 Correct 550 ms 32664 KB Output is correct
89 Correct 556 ms 32584 KB Output is correct
90 Correct 532 ms 32716 KB Output is correct
91 Correct 527 ms 32592 KB Output is correct
92 Correct 551 ms 32676 KB Output is correct
93 Correct 534 ms 45896 KB Output is correct
94 Correct 548 ms 46324 KB Output is correct
95 Correct 516 ms 45896 KB Output is correct
96 Correct 538 ms 45852 KB Output is correct
97 Correct 494 ms 45804 KB Output is correct
98 Correct 229 ms 30448 KB Output is correct
99 Correct 541 ms 46080 KB Output is correct
100 Correct 472 ms 45848 KB Output is correct
101 Correct 409 ms 34760 KB Output is correct
102 Correct 534 ms 45096 KB Output is correct
103 Correct 527 ms 44948 KB Output is correct
104 Correct 540 ms 45792 KB Output is correct
105 Correct 176 ms 27624 KB Output is correct
106 Correct 352 ms 44372 KB Output is correct
107 Correct 344 ms 44400 KB Output is correct
108 Correct 342 ms 44408 KB Output is correct
109 Correct 374 ms 44348 KB Output is correct
110 Correct 370 ms 44408 KB Output is correct
111 Correct 410 ms 44416 KB Output is correct
112 Correct 353 ms 44380 KB Output is correct
113 Correct 338 ms 44384 KB Output is correct
114 Correct 397 ms 44404 KB Output is correct
115 Correct 420 ms 44384 KB Output is correct
116 Correct 393 ms 44352 KB Output is correct