답안 #866321

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
866321 2023-10-25T21:14:40 Z danikoynov 원 고르기 (APIO18_circle_selection) C++14
100 / 100
894 ms 79732 KB
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;
 
struct point
{
    ll x, y;
 
    point(ll _x = 0, ll _y = 0)
    {
        x = _x;
        y = _y;
    }
 
    void get()
    {
        cin >> x >> y;
    }
};
 
struct circle
{
    point centre;
    ll radius;
    int idx;
 
    circle(point _centre = point(), ll _radius = 0, int _idx = 0)
    {
        centre = _centre;
        radius = _radius;
        idx = _idx;
    }
 
    void get()
    {
        centre.get();
        cin >> radius;
    }
};

ll get_distance(point A, point B)
{
    return (A.x - B.x) * (A.x - B.x) +
            (A.y - B.y) * (A.y - B.y);
}

bool intersect(circle c1, circle c2)
{
    ll distance = get_distance(c1.centre, c2.centre);

    return (distance <= (c1.radius + c2.radius) * (c1.radius + c2.radius));
        
}
const int maxn = 3e5 + 10;
const int inf = 1e9 + 10;
 
bool cmpx(circle c1, circle c2)
{
    return c1.centre.x < c2.centre.x;
}
 
bool cmpy(circle c1, circle c2)
{
    return c1.centre.y < c2.centre.y;
}
 

int n;
circle c[maxn], cx[maxn], cy[maxn];
void input()
{
    cin >> n;
    for (int i = 1; i <= n; i ++)
    {
        c[i].get();
        c[i].idx = i;
        cx[i] = cy[i] = c[i];
    }
}

void sort_arrays()
{
    sort(cx + 1, cx + n + 1, cmpx);
    sort(cy + 1, cy + n + 1, cmpy);
}
 
 
vector < vector < circle > > field;
bool eliminated[maxn];
int parent[maxn];
point comp[maxn];

void restructure(int block)
{
    field.clear();
    vector < int > dx;
    int last = -inf;
    for (int i = 1; i <= n; i ++)
    {
        if (eliminated[cx[i].idx])
            continue;
        
        int cur = cx[i].centre.x / block;
        if (cur != last)
            field.emplace_back();
        
        comp[cx[i].idx].x = field.size() - 1;
    
        last = cur;
    }

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

        comp[cy[i].idx].y = field[comp[cy[i].idx].x].size();
        field[comp[cy[i].idx].x].push_back(cy[i]);
    }


}
 
 
void simulate()
{
    int last_block = 0;
    for (int i = 1; i <= n; i ++)
        last_block = max(last_block, (int)c[i].radius);

    restructure(last_block);

    set < pair < int, int > > active;
    for (int i = 1; i <= n; i ++)
        active.insert({c[i].radius, -i});
    while(!active.empty())
    {

        int idx = -active.rbegin() -> second; 
        
        if (c[idx].radius <= last_block / 2)
        {
            last_block = c[idx].radius;
            restructure(last_block);
        }

        
        int cor_x = comp[idx].x, cor_y = comp[idx].y;
        for (int i = max(0, cor_x - 2); i < min((int)field.size(), cor_x + 3); i ++)
        {
            int lf = 0, rf = (int)(field[i].size()) - 1;
            while(lf <= rf)
            {
                int mf = (lf + rf) / 2;
                if (c[idx].centre.y / last_block - field[i][mf].centre.y / last_block > 2)
                    lf = mf + 1;
                else   
                    rf = mf - 1;
            }

            int lb = lf;

            lf = 0;
            rf = (int)(field[i].size()) - 1;
            while(lf <= rf)
            {
                int mf = (lf + rf) / 2;
                if (field[i][mf].centre.y / last_block - c[idx].centre.y / last_block > 2)
                    rf = mf - 1;
                else
                    lf = mf + 1;
            }

            int rb = rf;
            for (int j = lb; j <= rb; j ++)
            {
                if (eliminated[field[i][j].idx])
                    continue;
                if (intersect(field[i][j], c[idx]))
                {
                    parent[field[i][j].idx] = idx;
                    eliminated[field[i][j].idx] = 1;
                    active.erase({field[i][j].radius, -field[i][j].idx});
                }
            }
        }

    }

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

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
void solve()
{
    input();
    sort_arrays();
    simulate();
}
 
int main()
{
    speed();
    solve();
    return 0;
}

/**
 11
9 9 2
13 2 1
11 8 2
3 3 2
3 12 1
12 14 1
9 8 5
2 8 2
5 2 1
14 4 2
14 14 1

*/

Compilation message

circle_selection.cpp: In function 'void simulate()':
circle_selection.cpp:150:34: warning: unused variable 'cor_y' [-Wunused-variable]
  150 |         int cor_x = comp[idx].x, cor_y = comp[idx].y;
      |                                  ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 34648 KB Output is correct
2 Correct 7 ms 34652 KB Output is correct
3 Correct 5 ms 34652 KB Output is correct
4 Correct 5 ms 34652 KB Output is correct
5 Correct 5 ms 34580 KB Output is correct
6 Correct 6 ms 34652 KB Output is correct
7 Correct 5 ms 34652 KB Output is correct
8 Correct 6 ms 34652 KB Output is correct
9 Correct 5 ms 34652 KB Output is correct
10 Correct 6 ms 34768 KB Output is correct
11 Correct 6 ms 34648 KB Output is correct
12 Correct 5 ms 34652 KB Output is correct
13 Correct 5 ms 34652 KB Output is correct
14 Correct 5 ms 34648 KB Output is correct
15 Correct 6 ms 34904 KB Output is correct
16 Correct 6 ms 34652 KB Output is correct
17 Correct 6 ms 34652 KB Output is correct
18 Correct 6 ms 34652 KB Output is correct
19 Correct 9 ms 35132 KB Output is correct
20 Correct 10 ms 35164 KB Output is correct
21 Correct 9 ms 35104 KB Output is correct
22 Correct 10 ms 35324 KB Output is correct
23 Correct 11 ms 35164 KB Output is correct
24 Correct 10 ms 35240 KB Output is correct
25 Correct 10 ms 35356 KB Output is correct
26 Correct 10 ms 35184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 338 ms 59196 KB Output is correct
2 Correct 365 ms 60992 KB Output is correct
3 Correct 337 ms 60344 KB Output is correct
4 Correct 345 ms 58940 KB Output is correct
5 Correct 409 ms 64376 KB Output is correct
6 Correct 456 ms 71088 KB Output is correct
7 Correct 423 ms 67668 KB Output is correct
8 Correct 468 ms 67776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 34652 KB Output is correct
2 Correct 143 ms 45036 KB Output is correct
3 Correct 631 ms 69920 KB Output is correct
4 Correct 597 ms 69840 KB Output is correct
5 Correct 606 ms 68108 KB Output is correct
6 Correct 238 ms 52292 KB Output is correct
7 Correct 107 ms 44364 KB Output is correct
8 Correct 22 ms 36944 KB Output is correct
9 Correct 603 ms 69760 KB Output is correct
10 Correct 730 ms 70316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 407 ms 65884 KB Output is correct
2 Correct 377 ms 77180 KB Output is correct
3 Correct 435 ms 65988 KB Output is correct
4 Correct 375 ms 75696 KB Output is correct
5 Correct 408 ms 76976 KB Output is correct
6 Correct 397 ms 64540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 34648 KB Output is correct
2 Correct 7 ms 34652 KB Output is correct
3 Correct 5 ms 34652 KB Output is correct
4 Correct 5 ms 34652 KB Output is correct
5 Correct 5 ms 34580 KB Output is correct
6 Correct 6 ms 34652 KB Output is correct
7 Correct 5 ms 34652 KB Output is correct
8 Correct 6 ms 34652 KB Output is correct
9 Correct 5 ms 34652 KB Output is correct
10 Correct 6 ms 34768 KB Output is correct
11 Correct 6 ms 34648 KB Output is correct
12 Correct 5 ms 34652 KB Output is correct
13 Correct 5 ms 34652 KB Output is correct
14 Correct 5 ms 34648 KB Output is correct
15 Correct 6 ms 34904 KB Output is correct
16 Correct 6 ms 34652 KB Output is correct
17 Correct 6 ms 34652 KB Output is correct
18 Correct 6 ms 34652 KB Output is correct
19 Correct 9 ms 35132 KB Output is correct
20 Correct 10 ms 35164 KB Output is correct
21 Correct 9 ms 35104 KB Output is correct
22 Correct 10 ms 35324 KB Output is correct
23 Correct 11 ms 35164 KB Output is correct
24 Correct 10 ms 35240 KB Output is correct
25 Correct 10 ms 35356 KB Output is correct
26 Correct 10 ms 35184 KB Output is correct
27 Correct 13 ms 35544 KB Output is correct
28 Correct 13 ms 35544 KB Output is correct
29 Correct 13 ms 35540 KB Output is correct
30 Correct 16 ms 35676 KB Output is correct
31 Correct 15 ms 35868 KB Output is correct
32 Correct 15 ms 35868 KB Output is correct
33 Correct 101 ms 43360 KB Output is correct
34 Correct 104 ms 44232 KB Output is correct
35 Correct 108 ms 42408 KB Output is correct
36 Correct 167 ms 45264 KB Output is correct
37 Correct 135 ms 46784 KB Output is correct
38 Correct 134 ms 46536 KB Output is correct
39 Correct 180 ms 47556 KB Output is correct
40 Correct 185 ms 48772 KB Output is correct
41 Correct 178 ms 47916 KB Output is correct
42 Correct 114 ms 45540 KB Output is correct
43 Correct 112 ms 48524 KB Output is correct
44 Correct 109 ms 48472 KB Output is correct
45 Correct 106 ms 49248 KB Output is correct
46 Correct 96 ms 48536 KB Output is correct
47 Correct 107 ms 48464 KB Output is correct
48 Correct 101 ms 48440 KB Output is correct
49 Correct 100 ms 48968 KB Output is correct
50 Correct 94 ms 49088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 34648 KB Output is correct
2 Correct 7 ms 34652 KB Output is correct
3 Correct 5 ms 34652 KB Output is correct
4 Correct 5 ms 34652 KB Output is correct
5 Correct 5 ms 34580 KB Output is correct
6 Correct 6 ms 34652 KB Output is correct
7 Correct 5 ms 34652 KB Output is correct
8 Correct 6 ms 34652 KB Output is correct
9 Correct 5 ms 34652 KB Output is correct
10 Correct 6 ms 34768 KB Output is correct
11 Correct 6 ms 34648 KB Output is correct
12 Correct 5 ms 34652 KB Output is correct
13 Correct 5 ms 34652 KB Output is correct
14 Correct 5 ms 34648 KB Output is correct
15 Correct 6 ms 34904 KB Output is correct
16 Correct 6 ms 34652 KB Output is correct
17 Correct 6 ms 34652 KB Output is correct
18 Correct 6 ms 34652 KB Output is correct
19 Correct 9 ms 35132 KB Output is correct
20 Correct 10 ms 35164 KB Output is correct
21 Correct 9 ms 35104 KB Output is correct
22 Correct 10 ms 35324 KB Output is correct
23 Correct 11 ms 35164 KB Output is correct
24 Correct 10 ms 35240 KB Output is correct
25 Correct 10 ms 35356 KB Output is correct
26 Correct 10 ms 35184 KB Output is correct
27 Correct 338 ms 59196 KB Output is correct
28 Correct 365 ms 60992 KB Output is correct
29 Correct 337 ms 60344 KB Output is correct
30 Correct 345 ms 58940 KB Output is correct
31 Correct 409 ms 64376 KB Output is correct
32 Correct 456 ms 71088 KB Output is correct
33 Correct 423 ms 67668 KB Output is correct
34 Correct 468 ms 67776 KB Output is correct
35 Correct 5 ms 34652 KB Output is correct
36 Correct 143 ms 45036 KB Output is correct
37 Correct 631 ms 69920 KB Output is correct
38 Correct 597 ms 69840 KB Output is correct
39 Correct 606 ms 68108 KB Output is correct
40 Correct 238 ms 52292 KB Output is correct
41 Correct 107 ms 44364 KB Output is correct
42 Correct 22 ms 36944 KB Output is correct
43 Correct 603 ms 69760 KB Output is correct
44 Correct 730 ms 70316 KB Output is correct
45 Correct 407 ms 65884 KB Output is correct
46 Correct 377 ms 77180 KB Output is correct
47 Correct 435 ms 65988 KB Output is correct
48 Correct 375 ms 75696 KB Output is correct
49 Correct 408 ms 76976 KB Output is correct
50 Correct 397 ms 64540 KB Output is correct
51 Correct 13 ms 35544 KB Output is correct
52 Correct 13 ms 35544 KB Output is correct
53 Correct 13 ms 35540 KB Output is correct
54 Correct 16 ms 35676 KB Output is correct
55 Correct 15 ms 35868 KB Output is correct
56 Correct 15 ms 35868 KB Output is correct
57 Correct 101 ms 43360 KB Output is correct
58 Correct 104 ms 44232 KB Output is correct
59 Correct 108 ms 42408 KB Output is correct
60 Correct 167 ms 45264 KB Output is correct
61 Correct 135 ms 46784 KB Output is correct
62 Correct 134 ms 46536 KB Output is correct
63 Correct 180 ms 47556 KB Output is correct
64 Correct 185 ms 48772 KB Output is correct
65 Correct 178 ms 47916 KB Output is correct
66 Correct 114 ms 45540 KB Output is correct
67 Correct 112 ms 48524 KB Output is correct
68 Correct 109 ms 48472 KB Output is correct
69 Correct 106 ms 49248 KB Output is correct
70 Correct 96 ms 48536 KB Output is correct
71 Correct 107 ms 48464 KB Output is correct
72 Correct 101 ms 48440 KB Output is correct
73 Correct 100 ms 48968 KB Output is correct
74 Correct 94 ms 49088 KB Output is correct
75 Correct 453 ms 64520 KB Output is correct
76 Correct 410 ms 65436 KB Output is correct
77 Correct 417 ms 64944 KB Output is correct
78 Correct 371 ms 66800 KB Output is correct
79 Correct 461 ms 62924 KB Output is correct
80 Correct 376 ms 65968 KB Output is correct
81 Correct 636 ms 69708 KB Output is correct
82 Correct 643 ms 70712 KB Output is correct
83 Correct 678 ms 70088 KB Output is correct
84 Correct 616 ms 68944 KB Output is correct
85 Correct 609 ms 69648 KB Output is correct
86 Correct 576 ms 70348 KB Output is correct
87 Correct 672 ms 70532 KB Output is correct
88 Correct 788 ms 78736 KB Output is correct
89 Correct 798 ms 78276 KB Output is correct
90 Correct 784 ms 77264 KB Output is correct
91 Correct 803 ms 78012 KB Output is correct
92 Correct 894 ms 79732 KB Output is correct
93 Correct 556 ms 76704 KB Output is correct
94 Correct 631 ms 64948 KB Output is correct
95 Correct 486 ms 76172 KB Output is correct
96 Correct 610 ms 76960 KB Output is correct
97 Correct 860 ms 63176 KB Output is correct
98 Correct 602 ms 71752 KB Output is correct
99 Correct 628 ms 77140 KB Output is correct
100 Correct 487 ms 76020 KB Output is correct
101 Correct 547 ms 69304 KB Output is correct
102 Correct 519 ms 77120 KB Output is correct
103 Correct 837 ms 67072 KB Output is correct
104 Correct 512 ms 75536 KB Output is correct
105 Correct 410 ms 67592 KB Output is correct
106 Correct 391 ms 73900 KB Output is correct
107 Correct 376 ms 73552 KB Output is correct
108 Correct 375 ms 73576 KB Output is correct
109 Correct 389 ms 69700 KB Output is correct
110 Correct 386 ms 69944 KB Output is correct
111 Correct 377 ms 69696 KB Output is correct
112 Correct 361 ms 69444 KB Output is correct
113 Correct 366 ms 69424 KB Output is correct
114 Correct 361 ms 69852 KB Output is correct
115 Correct 379 ms 69436 KB Output is correct
116 Correct 378 ms 72332 KB Output is correct