답안 #811257

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
811257 2023-08-07T03:19:12 Z CYMario 원 고르기 (APIO18_circle_selection) C++17
100 / 100
717 ms 40972 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;
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;
}
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) / grid_r, (c[i].c.y) / 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) / grid_r, y = (c[idx[i]].c.y) / 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(' ');
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3820 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3816 KB Output is correct
6 Correct 2 ms 3796 KB Output is correct
7 Correct 2 ms 3796 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 3796 KB Output is correct
11 Correct 2 ms 3816 KB Output is correct
12 Correct 2 ms 3796 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 3824 KB Output is correct
16 Correct 2 ms 3796 KB Output is correct
17 Correct 2 ms 3824 KB Output is correct
18 Correct 2 ms 3796 KB Output is correct
19 Correct 5 ms 4180 KB Output is correct
20 Correct 3 ms 4184 KB Output is correct
21 Correct 5 ms 4088 KB Output is correct
22 Correct 5 ms 4436 KB Output is correct
23 Correct 5 ms 4464 KB Output is correct
24 Correct 5 ms 4440 KB Output is correct
25 Correct 5 ms 4436 KB Output is correct
26 Correct 5 ms 4436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 19264 KB Output is correct
2 Correct 90 ms 19288 KB Output is correct
3 Correct 85 ms 18928 KB Output is correct
4 Correct 86 ms 19248 KB Output is correct
5 Correct 156 ms 19236 KB Output is correct
6 Correct 225 ms 25960 KB Output is correct
7 Correct 129 ms 19768 KB Output is correct
8 Correct 158 ms 20804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3812 KB Output is correct
2 Correct 106 ms 17452 KB Output is correct
3 Correct 707 ms 40588 KB Output is correct
4 Correct 594 ms 40620 KB Output is correct
5 Correct 546 ms 34340 KB Output is correct
6 Correct 141 ms 19908 KB Output is correct
7 Correct 58 ms 13164 KB Output is correct
8 Correct 11 ms 5876 KB Output is correct
9 Correct 717 ms 39516 KB Output is correct
10 Correct 502 ms 33288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 428 ms 40612 KB Output is correct
2 Correct 440 ms 40768 KB Output is correct
3 Correct 140 ms 20404 KB Output is correct
4 Correct 447 ms 40972 KB Output is correct
5 Correct 442 ms 40740 KB Output is correct
6 Correct 113 ms 18784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3820 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3816 KB Output is correct
6 Correct 2 ms 3796 KB Output is correct
7 Correct 2 ms 3796 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 3796 KB Output is correct
11 Correct 2 ms 3816 KB Output is correct
12 Correct 2 ms 3796 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 3824 KB Output is correct
16 Correct 2 ms 3796 KB Output is correct
17 Correct 2 ms 3824 KB Output is correct
18 Correct 2 ms 3796 KB Output is correct
19 Correct 5 ms 4180 KB Output is correct
20 Correct 3 ms 4184 KB Output is correct
21 Correct 5 ms 4088 KB Output is correct
22 Correct 5 ms 4436 KB Output is correct
23 Correct 5 ms 4464 KB Output is correct
24 Correct 5 ms 4440 KB Output is correct
25 Correct 5 ms 4436 KB Output is correct
26 Correct 5 ms 4436 KB Output is correct
27 Correct 5 ms 4564 KB Output is correct
28 Correct 4 ms 4436 KB Output is correct
29 Correct 4 ms 4464 KB Output is correct
30 Correct 9 ms 5284 KB Output is correct
31 Correct 9 ms 5180 KB Output is correct
32 Correct 9 ms 5188 KB Output is correct
33 Correct 33 ms 9916 KB Output is correct
34 Correct 31 ms 9876 KB Output is correct
35 Correct 32 ms 9916 KB Output is correct
36 Correct 95 ms 17512 KB Output is correct
37 Correct 96 ms 17568 KB Output is correct
38 Correct 94 ms 17508 KB Output is correct
39 Correct 122 ms 13476 KB Output is correct
40 Correct 124 ms 13524 KB Output is correct
41 Correct 118 ms 13540 KB Output is correct
42 Correct 42 ms 11692 KB Output is correct
43 Correct 70 ms 17296 KB Output is correct
44 Correct 69 ms 17224 KB Output is correct
45 Correct 71 ms 17264 KB Output is correct
46 Correct 116 ms 17260 KB Output is correct
47 Correct 71 ms 17340 KB Output is correct
48 Correct 71 ms 17272 KB Output is correct
49 Correct 71 ms 17252 KB Output is correct
50 Correct 83 ms 17228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3820 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3816 KB Output is correct
6 Correct 2 ms 3796 KB Output is correct
7 Correct 2 ms 3796 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 3796 KB Output is correct
11 Correct 2 ms 3816 KB Output is correct
12 Correct 2 ms 3796 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 3824 KB Output is correct
16 Correct 2 ms 3796 KB Output is correct
17 Correct 2 ms 3824 KB Output is correct
18 Correct 2 ms 3796 KB Output is correct
19 Correct 5 ms 4180 KB Output is correct
20 Correct 3 ms 4184 KB Output is correct
21 Correct 5 ms 4088 KB Output is correct
22 Correct 5 ms 4436 KB Output is correct
23 Correct 5 ms 4464 KB Output is correct
24 Correct 5 ms 4440 KB Output is correct
25 Correct 5 ms 4436 KB Output is correct
26 Correct 5 ms 4436 KB Output is correct
27 Correct 115 ms 19264 KB Output is correct
28 Correct 90 ms 19288 KB Output is correct
29 Correct 85 ms 18928 KB Output is correct
30 Correct 86 ms 19248 KB Output is correct
31 Correct 156 ms 19236 KB Output is correct
32 Correct 225 ms 25960 KB Output is correct
33 Correct 129 ms 19768 KB Output is correct
34 Correct 158 ms 20804 KB Output is correct
35 Correct 2 ms 3812 KB Output is correct
36 Correct 106 ms 17452 KB Output is correct
37 Correct 707 ms 40588 KB Output is correct
38 Correct 594 ms 40620 KB Output is correct
39 Correct 546 ms 34340 KB Output is correct
40 Correct 141 ms 19908 KB Output is correct
41 Correct 58 ms 13164 KB Output is correct
42 Correct 11 ms 5876 KB Output is correct
43 Correct 717 ms 39516 KB Output is correct
44 Correct 502 ms 33288 KB Output is correct
45 Correct 428 ms 40612 KB Output is correct
46 Correct 440 ms 40768 KB Output is correct
47 Correct 140 ms 20404 KB Output is correct
48 Correct 447 ms 40972 KB Output is correct
49 Correct 442 ms 40740 KB Output is correct
50 Correct 113 ms 18784 KB Output is correct
51 Correct 5 ms 4564 KB Output is correct
52 Correct 4 ms 4436 KB Output is correct
53 Correct 4 ms 4464 KB Output is correct
54 Correct 9 ms 5284 KB Output is correct
55 Correct 9 ms 5180 KB Output is correct
56 Correct 9 ms 5188 KB Output is correct
57 Correct 33 ms 9916 KB Output is correct
58 Correct 31 ms 9876 KB Output is correct
59 Correct 32 ms 9916 KB Output is correct
60 Correct 95 ms 17512 KB Output is correct
61 Correct 96 ms 17568 KB Output is correct
62 Correct 94 ms 17508 KB Output is correct
63 Correct 122 ms 13476 KB Output is correct
64 Correct 124 ms 13524 KB Output is correct
65 Correct 118 ms 13540 KB Output is correct
66 Correct 42 ms 11692 KB Output is correct
67 Correct 70 ms 17296 KB Output is correct
68 Correct 69 ms 17224 KB Output is correct
69 Correct 71 ms 17264 KB Output is correct
70 Correct 116 ms 17260 KB Output is correct
71 Correct 71 ms 17340 KB Output is correct
72 Correct 71 ms 17272 KB Output is correct
73 Correct 71 ms 17252 KB Output is correct
74 Correct 83 ms 17228 KB Output is correct
75 Correct 96 ms 18968 KB Output is correct
76 Correct 99 ms 19184 KB Output is correct
77 Correct 104 ms 19296 KB Output is correct
78 Correct 89 ms 18940 KB Output is correct
79 Correct 130 ms 19176 KB Output is correct
80 Correct 89 ms 18996 KB Output is correct
81 Correct 599 ms 40664 KB Output is correct
82 Correct 570 ms 40644 KB Output is correct
83 Correct 602 ms 40644 KB Output is correct
84 Correct 602 ms 40616 KB Output is correct
85 Correct 610 ms 40648 KB Output is correct
86 Correct 592 ms 40644 KB Output is correct
87 Correct 608 ms 40276 KB Output is correct
88 Correct 537 ms 30956 KB Output is correct
89 Correct 545 ms 30872 KB Output is correct
90 Correct 523 ms 30956 KB Output is correct
91 Correct 531 ms 30872 KB Output is correct
92 Correct 512 ms 30900 KB Output is correct
93 Correct 535 ms 40732 KB Output is correct
94 Correct 557 ms 40300 KB Output is correct
95 Correct 573 ms 40656 KB Output is correct
96 Correct 564 ms 40548 KB Output is correct
97 Correct 570 ms 40780 KB Output is correct
98 Correct 230 ms 24540 KB Output is correct
99 Correct 559 ms 40572 KB Output is correct
100 Correct 486 ms 40776 KB Output is correct
101 Correct 370 ms 29304 KB Output is correct
102 Correct 519 ms 39576 KB Output is correct
103 Correct 551 ms 39820 KB Output is correct
104 Correct 601 ms 40636 KB Output is correct
105 Correct 182 ms 24400 KB Output is correct
106 Correct 364 ms 38308 KB Output is correct
107 Correct 364 ms 38212 KB Output is correct
108 Correct 353 ms 38260 KB Output is correct
109 Correct 365 ms 38276 KB Output is correct
110 Correct 391 ms 38268 KB Output is correct
111 Correct 357 ms 38384 KB Output is correct
112 Correct 372 ms 38264 KB Output is correct
113 Correct 371 ms 38276 KB Output is correct
114 Correct 396 ms 38312 KB Output is correct
115 Correct 350 ms 38192 KB Output is correct
116 Correct 366 ms 38248 KB Output is correct