답안 #160536

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
160536 2019-10-28T10:56:39 Z Minnakhmetov 원 고르기 (APIO18_circle_selection) C++14
100 / 100
1462 ms 47264 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;
unordered_map<ll, vector<int>> mp;
bool used[N];
C cir[N];
int n;
int ans[N];

ll getNum(ll x, ll y) {
    return (x << 31) + y;
}

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[getNum(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]) {
            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++) {
                    ll num = getNum(j, k);
                    if (mp.count(num)) {
                        vector<int> &v = mp[num];
                        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:75: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 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 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 376 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 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 6 ms 760 KB Output is correct
20 Correct 6 ms 760 KB Output is correct
21 Correct 6 ms 760 KB Output is correct
22 Correct 12 ms 1272 KB Output is correct
23 Correct 13 ms 1272 KB Output is correct
24 Correct 12 ms 1144 KB Output is correct
25 Correct 12 ms 1144 KB Output is correct
26 Correct 12 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 217 ms 20344 KB Output is correct
2 Correct 221 ms 20332 KB Output is correct
3 Correct 223 ms 21096 KB Output is correct
4 Correct 208 ms 20604 KB Output is correct
5 Correct 254 ms 18596 KB Output is correct
6 Correct 594 ms 31164 KB Output is correct
7 Correct 270 ms 19704 KB Output is correct
8 Correct 334 ms 23336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 314 ms 16032 KB Output is correct
3 Correct 1204 ms 47160 KB Output is correct
4 Correct 1212 ms 47264 KB Output is correct
5 Correct 1087 ms 42392 KB Output is correct
6 Correct 410 ms 22076 KB Output is correct
7 Correct 175 ms 11908 KB Output is correct
8 Correct 29 ms 2936 KB Output is correct
9 Correct 1428 ms 45292 KB Output is correct
10 Correct 1331 ms 39648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1454 ms 47164 KB Output is correct
2 Correct 1404 ms 46076 KB Output is correct
3 Correct 365 ms 26736 KB Output is correct
4 Correct 1409 ms 46068 KB Output is correct
5 Correct 1462 ms 46084 KB Output is correct
6 Correct 271 ms 21952 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 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 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 376 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 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 6 ms 760 KB Output is correct
20 Correct 6 ms 760 KB Output is correct
21 Correct 6 ms 760 KB Output is correct
22 Correct 12 ms 1272 KB Output is correct
23 Correct 13 ms 1272 KB Output is correct
24 Correct 12 ms 1144 KB Output is correct
25 Correct 12 ms 1144 KB Output is correct
26 Correct 12 ms 1144 KB Output is correct
27 Correct 10 ms 1144 KB Output is correct
28 Correct 9 ms 1116 KB Output is correct
29 Correct 9 ms 1144 KB Output is correct
30 Correct 24 ms 1912 KB Output is correct
31 Correct 24 ms 1912 KB Output is correct
32 Correct 26 ms 1912 KB Output is correct
33 Correct 78 ms 8184 KB Output is correct
34 Correct 80 ms 8308 KB Output is correct
35 Correct 80 ms 7716 KB Output is correct
36 Correct 336 ms 15748 KB Output is correct
37 Correct 345 ms 16008 KB Output is correct
38 Correct 478 ms 15936 KB Output is correct
39 Correct 320 ms 13212 KB Output is correct
40 Correct 339 ms 13160 KB Output is correct
41 Correct 296 ms 13356 KB Output is correct
42 Correct 151 ms 14912 KB Output is correct
43 Correct 357 ms 15664 KB Output is correct
44 Correct 344 ms 15800 KB Output is correct
45 Correct 320 ms 15752 KB Output is correct
46 Correct 330 ms 15752 KB Output is correct
47 Correct 298 ms 15684 KB Output is correct
48 Correct 321 ms 15624 KB Output is correct
49 Correct 327 ms 15748 KB Output is correct
50 Correct 346 ms 15752 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 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 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 376 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 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 6 ms 760 KB Output is correct
20 Correct 6 ms 760 KB Output is correct
21 Correct 6 ms 760 KB Output is correct
22 Correct 12 ms 1272 KB Output is correct
23 Correct 13 ms 1272 KB Output is correct
24 Correct 12 ms 1144 KB Output is correct
25 Correct 12 ms 1144 KB Output is correct
26 Correct 12 ms 1144 KB Output is correct
27 Correct 217 ms 20344 KB Output is correct
28 Correct 221 ms 20332 KB Output is correct
29 Correct 223 ms 21096 KB Output is correct
30 Correct 208 ms 20604 KB Output is correct
31 Correct 254 ms 18596 KB Output is correct
32 Correct 594 ms 31164 KB Output is correct
33 Correct 270 ms 19704 KB Output is correct
34 Correct 334 ms 23336 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 314 ms 16032 KB Output is correct
37 Correct 1204 ms 47160 KB Output is correct
38 Correct 1212 ms 47264 KB Output is correct
39 Correct 1087 ms 42392 KB Output is correct
40 Correct 410 ms 22076 KB Output is correct
41 Correct 175 ms 11908 KB Output is correct
42 Correct 29 ms 2936 KB Output is correct
43 Correct 1428 ms 45292 KB Output is correct
44 Correct 1331 ms 39648 KB Output is correct
45 Correct 1454 ms 47164 KB Output is correct
46 Correct 1404 ms 46076 KB Output is correct
47 Correct 365 ms 26736 KB Output is correct
48 Correct 1409 ms 46068 KB Output is correct
49 Correct 1462 ms 46084 KB Output is correct
50 Correct 271 ms 21952 KB Output is correct
51 Correct 10 ms 1144 KB Output is correct
52 Correct 9 ms 1116 KB Output is correct
53 Correct 9 ms 1144 KB Output is correct
54 Correct 24 ms 1912 KB Output is correct
55 Correct 24 ms 1912 KB Output is correct
56 Correct 26 ms 1912 KB Output is correct
57 Correct 78 ms 8184 KB Output is correct
58 Correct 80 ms 8308 KB Output is correct
59 Correct 80 ms 7716 KB Output is correct
60 Correct 336 ms 15748 KB Output is correct
61 Correct 345 ms 16008 KB Output is correct
62 Correct 478 ms 15936 KB Output is correct
63 Correct 320 ms 13212 KB Output is correct
64 Correct 339 ms 13160 KB Output is correct
65 Correct 296 ms 13356 KB Output is correct
66 Correct 151 ms 14912 KB Output is correct
67 Correct 357 ms 15664 KB Output is correct
68 Correct 344 ms 15800 KB Output is correct
69 Correct 320 ms 15752 KB Output is correct
70 Correct 330 ms 15752 KB Output is correct
71 Correct 298 ms 15684 KB Output is correct
72 Correct 321 ms 15624 KB Output is correct
73 Correct 327 ms 15748 KB Output is correct
74 Correct 346 ms 15752 KB Output is correct
75 Correct 285 ms 18684 KB Output is correct
76 Correct 240 ms 19052 KB Output is correct
77 Correct 228 ms 20168 KB Output is correct
78 Correct 231 ms 19940 KB Output is correct
79 Correct 285 ms 19040 KB Output is correct
80 Correct 231 ms 19976 KB Output is correct
81 Correct 1308 ms 45804 KB Output is correct
82 Correct 1303 ms 46004 KB Output is correct
83 Correct 1257 ms 45964 KB Output is correct
84 Correct 1275 ms 45664 KB Output is correct
85 Correct 1283 ms 45828 KB Output is correct
86 Correct 1286 ms 45832 KB Output is correct
87 Correct 1284 ms 45444 KB Output is correct
88 Correct 1158 ms 40036 KB Output is correct
89 Correct 1139 ms 40064 KB Output is correct
90 Correct 1195 ms 40264 KB Output is correct
91 Correct 1235 ms 40136 KB Output is correct
92 Correct 1158 ms 40112 KB Output is correct
93 Correct 1264 ms 45624 KB Output is correct
94 Correct 1245 ms 45504 KB Output is correct
95 Correct 1246 ms 45712 KB Output is correct
96 Correct 1272 ms 45516 KB Output is correct
97 Correct 1351 ms 45700 KB Output is correct
98 Correct 699 ms 35264 KB Output is correct
99 Correct 1309 ms 45352 KB Output is correct
100 Correct 1288 ms 45692 KB Output is correct
101 Correct 850 ms 40580 KB Output is correct
102 Correct 1233 ms 45036 KB Output is correct
103 Correct 1339 ms 45160 KB Output is correct
104 Correct 1253 ms 45448 KB Output is correct
105 Correct 636 ms 44960 KB Output is correct
106 Correct 1182 ms 43684 KB Output is correct
107 Correct 1189 ms 43676 KB Output is correct
108 Correct 1166 ms 43568 KB Output is correct
109 Correct 1149 ms 43444 KB Output is correct
110 Correct 1134 ms 43252 KB Output is correct
111 Correct 1111 ms 43368 KB Output is correct
112 Correct 1138 ms 43240 KB Output is correct
113 Correct 1163 ms 42928 KB Output is correct
114 Correct 1155 ms 42956 KB Output is correct
115 Correct 1315 ms 43012 KB Output is correct
116 Correct 1259 ms 42880 KB Output is correct