답안 #160535

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
160535 2019-10-28T10:51:16 Z Minnakhmetov 원 고르기 (APIO18_circle_selection) C++14
100 / 100
2536 ms 54616 KB
#include <bits/stdc++.h>
    
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
  
using namespace std;

struct C {
    ll x, y, r, i;
};

const int N = 3e5 + 5, INF = 1e9;
map<pair<ll, ll>, vector<int>> mp;
bool used[N];
C cir[N];
int n;
int ans[N];

bool check(const C &a, const C &b) {
    return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) <= 
        (a.r + b.r) * (a.r + b.r);
}

void build(int r) {
    mp.clear();
    for (int i = 0; i < n; i++) {
        if (!used[i]) {
            mp[{cir[i].x / r, cir[i].y / r}].push_back(i);
        }
    }
}
 
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    cin >> n;

    int cur = 0;

    for (int i = 0; i < n; i++) {
        cin >> cir[i].x >> cir[i].y >> cir[i].r;
        cir[i].x += INF;
        cir[i].y += INF;
        cir[i].i = i;
    }

    sort(cir, cir + n, [](const C &a, const C &b) {
        return a.r == b.r ? a.i < b.i : a.r > b.r;
    });

    cur = cir[0].r;

    build(cur);

    for (int i = 0; i < n; i++) {
        if (!used[i]) {
            // cout << cir[i].x << " " << cir[i].y << " " << cir[i].r << "\n";

            if (cir[i].r * 2 < cur) {
                cur = cir[i].r;
                build(cur);
            }

            int x = cir[i].x / cur,
                y = cir[i].y / cur;

            for (int j = x - 2; j <= x + 2; j++) {
                for (int k = y - 2; k <= y + 2; k++) {
                    if (mp.count({j, k})) {
                        vector<int> &v = mp[{j, k}];
                        for (int h = 0; h < v.size(); h++) {
                            if (check(cir[i], cir[v[h]])) {
                                ans[cir[v[h]].i] = cir[i].i;
                                used[v[h]] = 1;
                                swap(v.back(), v[h]);
                                v.pop_back();
                                h--;
                            }
                        }
                    }
                    
                }
            }
        }
    }

    for (int i = 0; i < n; i++) {
        cout << ans[i] + 1 << " ";
    }
 
    return 0;
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:72:43: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                         for (int h = 0; h < v.size(); h++) {
                                         ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 6 ms 760 KB Output is correct
20 Correct 6 ms 760 KB Output is correct
21 Correct 5 ms 760 KB Output is correct
22 Correct 17 ms 1272 KB Output is correct
23 Correct 18 ms 1272 KB Output is correct
24 Correct 18 ms 1272 KB Output is correct
25 Correct 16 ms 1272 KB Output is correct
26 Correct 17 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 205 ms 15616 KB Output is correct
2 Correct 210 ms 15672 KB Output is correct
3 Correct 204 ms 16360 KB Output is correct
4 Correct 207 ms 15784 KB Output is correct
5 Correct 286 ms 16148 KB Output is correct
6 Correct 1073 ms 30584 KB Output is correct
7 Correct 334 ms 16432 KB Output is correct
8 Correct 459 ms 20628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 555 ms 17464 KB Output is correct
3 Correct 2236 ms 48024 KB Output is correct
4 Correct 2322 ms 48176 KB Output is correct
5 Correct 2300 ms 41804 KB Output is correct
6 Correct 734 ms 20624 KB Output is correct
7 Correct 295 ms 11844 KB Output is correct
8 Correct 42 ms 3064 KB Output is correct
9 Correct 2501 ms 46352 KB Output is correct
10 Correct 1992 ms 46728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1883 ms 48072 KB Output is correct
2 Correct 1396 ms 47224 KB Output is correct
3 Correct 601 ms 23928 KB Output is correct
4 Correct 1451 ms 47164 KB Output is correct
5 Correct 1446 ms 47216 KB Output is correct
6 Correct 335 ms 17656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 6 ms 760 KB Output is correct
20 Correct 6 ms 760 KB Output is correct
21 Correct 5 ms 760 KB Output is correct
22 Correct 17 ms 1272 KB Output is correct
23 Correct 18 ms 1272 KB Output is correct
24 Correct 18 ms 1272 KB Output is correct
25 Correct 16 ms 1272 KB Output is correct
26 Correct 17 ms 1272 KB Output is correct
27 Correct 9 ms 1144 KB Output is correct
28 Correct 9 ms 1148 KB Output is correct
29 Correct 9 ms 1184 KB Output is correct
30 Correct 37 ms 2168 KB Output is correct
31 Correct 37 ms 2168 KB Output is correct
32 Correct 35 ms 2172 KB Output is correct
33 Correct 76 ms 7044 KB Output is correct
34 Correct 77 ms 7220 KB Output is correct
35 Correct 86 ms 6740 KB Output is correct
36 Correct 538 ms 17796 KB Output is correct
37 Correct 538 ms 17656 KB Output is correct
38 Correct 528 ms 17656 KB Output is correct
39 Correct 509 ms 15192 KB Output is correct
40 Correct 452 ms 14956 KB Output is correct
41 Correct 444 ms 14992 KB Output is correct
42 Correct 372 ms 16440 KB Output is correct
43 Correct 483 ms 16348 KB Output is correct
44 Correct 386 ms 16376 KB Output is correct
45 Correct 393 ms 16376 KB Output is correct
46 Correct 414 ms 16248 KB Output is correct
47 Correct 412 ms 16264 KB Output is correct
48 Correct 378 ms 16376 KB Output is correct
49 Correct 386 ms 16464 KB Output is correct
50 Correct 386 ms 16248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 6 ms 760 KB Output is correct
20 Correct 6 ms 760 KB Output is correct
21 Correct 5 ms 760 KB Output is correct
22 Correct 17 ms 1272 KB Output is correct
23 Correct 18 ms 1272 KB Output is correct
24 Correct 18 ms 1272 KB Output is correct
25 Correct 16 ms 1272 KB Output is correct
26 Correct 17 ms 1272 KB Output is correct
27 Correct 205 ms 15616 KB Output is correct
28 Correct 210 ms 15672 KB Output is correct
29 Correct 204 ms 16360 KB Output is correct
30 Correct 207 ms 15784 KB Output is correct
31 Correct 286 ms 16148 KB Output is correct
32 Correct 1073 ms 30584 KB Output is correct
33 Correct 334 ms 16432 KB Output is correct
34 Correct 459 ms 20628 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 555 ms 17464 KB Output is correct
37 Correct 2236 ms 48024 KB Output is correct
38 Correct 2322 ms 48176 KB Output is correct
39 Correct 2300 ms 41804 KB Output is correct
40 Correct 734 ms 20624 KB Output is correct
41 Correct 295 ms 11844 KB Output is correct
42 Correct 42 ms 3064 KB Output is correct
43 Correct 2501 ms 46352 KB Output is correct
44 Correct 1992 ms 46728 KB Output is correct
45 Correct 1883 ms 48072 KB Output is correct
46 Correct 1396 ms 47224 KB Output is correct
47 Correct 601 ms 23928 KB Output is correct
48 Correct 1451 ms 47164 KB Output is correct
49 Correct 1446 ms 47216 KB Output is correct
50 Correct 335 ms 17656 KB Output is correct
51 Correct 9 ms 1144 KB Output is correct
52 Correct 9 ms 1148 KB Output is correct
53 Correct 9 ms 1184 KB Output is correct
54 Correct 37 ms 2168 KB Output is correct
55 Correct 37 ms 2168 KB Output is correct
56 Correct 35 ms 2172 KB Output is correct
57 Correct 76 ms 7044 KB Output is correct
58 Correct 77 ms 7220 KB Output is correct
59 Correct 86 ms 6740 KB Output is correct
60 Correct 538 ms 17796 KB Output is correct
61 Correct 538 ms 17656 KB Output is correct
62 Correct 528 ms 17656 KB Output is correct
63 Correct 509 ms 15192 KB Output is correct
64 Correct 452 ms 14956 KB Output is correct
65 Correct 444 ms 14992 KB Output is correct
66 Correct 372 ms 16440 KB Output is correct
67 Correct 483 ms 16348 KB Output is correct
68 Correct 386 ms 16376 KB Output is correct
69 Correct 393 ms 16376 KB Output is correct
70 Correct 414 ms 16248 KB Output is correct
71 Correct 412 ms 16264 KB Output is correct
72 Correct 378 ms 16376 KB Output is correct
73 Correct 386 ms 16464 KB Output is correct
74 Correct 386 ms 16248 KB Output is correct
75 Correct 240 ms 22440 KB Output is correct
76 Correct 233 ms 22384 KB Output is correct
77 Correct 222 ms 23780 KB Output is correct
78 Correct 227 ms 23528 KB Output is correct
79 Correct 271 ms 22072 KB Output is correct
80 Correct 229 ms 23464 KB Output is correct
81 Correct 2201 ms 54264 KB Output is correct
82 Correct 2047 ms 54084 KB Output is correct
83 Correct 2209 ms 54176 KB Output is correct
84 Correct 2291 ms 54616 KB Output is correct
85 Correct 2159 ms 54164 KB Output is correct
86 Correct 2077 ms 54264 KB Output is correct
87 Correct 2435 ms 53924 KB Output is correct
88 Correct 1664 ms 44720 KB Output is correct
89 Correct 1662 ms 44448 KB Output is correct
90 Correct 1651 ms 44796 KB Output is correct
91 Correct 1629 ms 44680 KB Output is correct
92 Correct 1641 ms 44732 KB Output is correct
93 Correct 1586 ms 52960 KB Output is correct
94 Correct 1883 ms 53340 KB Output is correct
95 Correct 1665 ms 53112 KB Output is correct
96 Correct 1984 ms 53240 KB Output is correct
97 Correct 2536 ms 53160 KB Output is correct
98 Correct 1079 ms 41256 KB Output is correct
99 Correct 1614 ms 53240 KB Output is correct
100 Correct 1408 ms 52872 KB Output is correct
101 Correct 1468 ms 46460 KB Output is correct
102 Correct 1635 ms 52600 KB Output is correct
103 Correct 2433 ms 52600 KB Output is correct
104 Correct 1647 ms 52884 KB Output is correct
105 Correct 1328 ms 50740 KB Output is correct
106 Correct 1352 ms 51800 KB Output is correct
107 Correct 1311 ms 51708 KB Output is correct
108 Correct 1330 ms 51812 KB Output is correct
109 Correct 1310 ms 51728 KB Output is correct
110 Correct 1400 ms 51736 KB Output is correct
111 Correct 1330 ms 51792 KB Output is correct
112 Correct 1306 ms 51832 KB Output is correct
113 Correct 1308 ms 51832 KB Output is correct
114 Correct 1300 ms 51684 KB Output is correct
115 Correct 1307 ms 51800 KB Output is correct
116 Correct 1252 ms 51616 KB Output is correct