Submission #258765

# Submission time Handle Problem Language Result Execution time Memory
258765 2020-08-06T14:19:42 Z Mercenary Circle selection (APIO18_circle_selection) C++14
100 / 100
1168 ms 26756 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 3e5 + 5;
const int logn = log2(maxn) + 1;
int ans[maxn];
int n;

struct circle{
    int x , y , r , id;
    bool operator < (const circle & other){
        return mp(x,y) < mp(other.x,other.y);
    }
}a[maxn] , b[maxn] , c[maxn];

bool intersect(circle & a , circle & b){
    return 1ll * (a.r + b.r) * (a.r + b.r) >= 1ll * (a.x - b.x) * (a.x - b.x) + 1ll * (a.y - b.y) * (a.y - b.y);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n;
    for(int i = 1 ; i <= n ; ++i){
        cin >> a[i].x >> a[i].y >> a[i].r;
        a[i].id = i;
        c[i] = a[i];
    }
    sort(a + 1 , a + n + 1 ,[&](const circle & x , const circle &y){
            return mp(x.r , -x.id) > mp(y.r , -y.id);
         });
    int cur = a[1].r * 2;
    for(int i = 1 ; i <= n ; ++i){
        if(ans[a[i].id] > 0)continue;
        if(a[i].r <= cur / 2){
            cur /= 2;
            for(int j = 1 ; j <= n ; ++j){
                b[j].x = a[j].x / cur;
                b[j].y = a[j].y / cur;
                b[j].id = a[j].id;
            }
            sort(b + 1 , b + n + 1);
        }
        ans[a[i].id] = a[i].id;
        int x = a[i].x / cur;
        int y = a[i].y / cur;
        for(int j = x - 2 ; j <= x + 2 ; ++j){
            auto it = lower_bound(b + 1 , b + n + 1, circle{j , y - 3 , 0 , 0}) - b;
            while(it <= n && b[it].x == j && b[it].y <= y + 2){
                if(ans[b[it].id] == 0 && intersect(a[i] , c[b[it].id]))ans[b[it].id] = a[i].id;
                ++it;
            }
        }
    }
    for(int i = 1 ; i <= n ; ++i)cout << ans[i] << ' ';
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:38:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:39:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".OUT", "w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 4 ms 768 KB Output is correct
20 Correct 3 ms 768 KB Output is correct
21 Correct 5 ms 768 KB Output is correct
22 Correct 12 ms 768 KB Output is correct
23 Correct 13 ms 768 KB Output is correct
24 Correct 12 ms 768 KB Output is correct
25 Correct 11 ms 768 KB Output is correct
26 Correct 11 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 204 ms 24440 KB Output is correct
2 Correct 209 ms 24612 KB Output is correct
3 Correct 192 ms 24056 KB Output is correct
4 Correct 202 ms 24444 KB Output is correct
5 Correct 357 ms 22136 KB Output is correct
6 Correct 473 ms 22264 KB Output is correct
7 Correct 445 ms 22392 KB Output is correct
8 Correct 460 ms 22264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 349 ms 8792 KB Output is correct
3 Correct 1168 ms 25720 KB Output is correct
4 Correct 1101 ms 25720 KB Output is correct
5 Correct 1119 ms 25336 KB Output is correct
6 Correct 317 ms 13836 KB Output is correct
7 Correct 145 ms 7300 KB Output is correct
8 Correct 25 ms 1784 KB Output is correct
9 Correct 1109 ms 25704 KB Output is correct
10 Correct 646 ms 25980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 443 ms 25464 KB Output is correct
2 Correct 425 ms 24696 KB Output is correct
3 Correct 238 ms 25592 KB Output is correct
4 Correct 429 ms 25104 KB Output is correct
5 Correct 411 ms 25208 KB Output is correct
6 Correct 212 ms 25464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 4 ms 768 KB Output is correct
20 Correct 3 ms 768 KB Output is correct
21 Correct 5 ms 768 KB Output is correct
22 Correct 12 ms 768 KB Output is correct
23 Correct 13 ms 768 KB Output is correct
24 Correct 12 ms 768 KB Output is correct
25 Correct 11 ms 768 KB Output is correct
26 Correct 11 ms 768 KB Output is correct
27 Correct 13 ms 1280 KB Output is correct
28 Correct 7 ms 1280 KB Output is correct
29 Correct 7 ms 1280 KB Output is correct
30 Correct 25 ms 1152 KB Output is correct
31 Correct 24 ms 1152 KB Output is correct
32 Correct 25 ms 1152 KB Output is correct
33 Correct 68 ms 9208 KB Output is correct
34 Correct 68 ms 9208 KB Output is correct
35 Correct 207 ms 9080 KB Output is correct
36 Correct 297 ms 8568 KB Output is correct
37 Correct 299 ms 8696 KB Output is correct
38 Correct 312 ms 8708 KB Output is correct
39 Correct 249 ms 7160 KB Output is correct
40 Correct 248 ms 7164 KB Output is correct
41 Correct 246 ms 7164 KB Output is correct
42 Correct 77 ms 7672 KB Output is correct
43 Correct 112 ms 8812 KB Output is correct
44 Correct 112 ms 8696 KB Output is correct
45 Correct 113 ms 8696 KB Output is correct
46 Correct 122 ms 8636 KB Output is correct
47 Correct 114 ms 8696 KB Output is correct
48 Correct 114 ms 8696 KB Output is correct
49 Correct 116 ms 8696 KB Output is correct
50 Correct 114 ms 8696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 4 ms 768 KB Output is correct
20 Correct 3 ms 768 KB Output is correct
21 Correct 5 ms 768 KB Output is correct
22 Correct 12 ms 768 KB Output is correct
23 Correct 13 ms 768 KB Output is correct
24 Correct 12 ms 768 KB Output is correct
25 Correct 11 ms 768 KB Output is correct
26 Correct 11 ms 768 KB Output is correct
27 Correct 204 ms 24440 KB Output is correct
28 Correct 209 ms 24612 KB Output is correct
29 Correct 192 ms 24056 KB Output is correct
30 Correct 202 ms 24444 KB Output is correct
31 Correct 357 ms 22136 KB Output is correct
32 Correct 473 ms 22264 KB Output is correct
33 Correct 445 ms 22392 KB Output is correct
34 Correct 460 ms 22264 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 349 ms 8792 KB Output is correct
37 Correct 1168 ms 25720 KB Output is correct
38 Correct 1101 ms 25720 KB Output is correct
39 Correct 1119 ms 25336 KB Output is correct
40 Correct 317 ms 13836 KB Output is correct
41 Correct 145 ms 7300 KB Output is correct
42 Correct 25 ms 1784 KB Output is correct
43 Correct 1109 ms 25704 KB Output is correct
44 Correct 646 ms 25980 KB Output is correct
45 Correct 443 ms 25464 KB Output is correct
46 Correct 425 ms 24696 KB Output is correct
47 Correct 238 ms 25592 KB Output is correct
48 Correct 429 ms 25104 KB Output is correct
49 Correct 411 ms 25208 KB Output is correct
50 Correct 212 ms 25464 KB Output is correct
51 Correct 13 ms 1280 KB Output is correct
52 Correct 7 ms 1280 KB Output is correct
53 Correct 7 ms 1280 KB Output is correct
54 Correct 25 ms 1152 KB Output is correct
55 Correct 24 ms 1152 KB Output is correct
56 Correct 25 ms 1152 KB Output is correct
57 Correct 68 ms 9208 KB Output is correct
58 Correct 68 ms 9208 KB Output is correct
59 Correct 207 ms 9080 KB Output is correct
60 Correct 297 ms 8568 KB Output is correct
61 Correct 299 ms 8696 KB Output is correct
62 Correct 312 ms 8708 KB Output is correct
63 Correct 249 ms 7160 KB Output is correct
64 Correct 248 ms 7164 KB Output is correct
65 Correct 246 ms 7164 KB Output is correct
66 Correct 77 ms 7672 KB Output is correct
67 Correct 112 ms 8812 KB Output is correct
68 Correct 112 ms 8696 KB Output is correct
69 Correct 113 ms 8696 KB Output is correct
70 Correct 122 ms 8636 KB Output is correct
71 Correct 114 ms 8696 KB Output is correct
72 Correct 114 ms 8696 KB Output is correct
73 Correct 116 ms 8696 KB Output is correct
74 Correct 114 ms 8696 KB Output is correct
75 Correct 645 ms 26756 KB Output is correct
76 Correct 245 ms 26616 KB Output is correct
77 Correct 206 ms 26616 KB Output is correct
78 Correct 200 ms 26488 KB Output is correct
79 Correct 793 ms 26360 KB Output is correct
80 Correct 202 ms 26488 KB Output is correct
81 Correct 1026 ms 25720 KB Output is correct
82 Correct 1036 ms 25720 KB Output is correct
83 Correct 1006 ms 25492 KB Output is correct
84 Correct 1049 ms 25968 KB Output is correct
85 Correct 1024 ms 25592 KB Output is correct
86 Correct 1022 ms 25636 KB Output is correct
87 Correct 1084 ms 25720 KB Output is correct
88 Correct 887 ms 20948 KB Output is correct
89 Correct 880 ms 20872 KB Output is correct
90 Correct 851 ms 20856 KB Output is correct
91 Correct 873 ms 20812 KB Output is correct
92 Correct 863 ms 20856 KB Output is correct
93 Correct 575 ms 24568 KB Output is correct
94 Correct 554 ms 25084 KB Output is correct
95 Correct 571 ms 24568 KB Output is correct
96 Correct 625 ms 24568 KB Output is correct
97 Correct 627 ms 24440 KB Output is correct
98 Correct 584 ms 24952 KB Output is correct
99 Correct 615 ms 24696 KB Output is correct
100 Correct 489 ms 24440 KB Output is correct
101 Correct 632 ms 24952 KB Output is correct
102 Correct 607 ms 24568 KB Output is correct
103 Correct 715 ms 24700 KB Output is correct
104 Correct 614 ms 24440 KB Output is correct
105 Correct 253 ms 22264 KB Output is correct
106 Correct 350 ms 25336 KB Output is correct
107 Correct 358 ms 25336 KB Output is correct
108 Correct 353 ms 25336 KB Output is correct
109 Correct 357 ms 25464 KB Output is correct
110 Correct 359 ms 25464 KB Output is correct
111 Correct 370 ms 25464 KB Output is correct
112 Correct 375 ms 25336 KB Output is correct
113 Correct 367 ms 25336 KB Output is correct
114 Correct 368 ms 25592 KB Output is correct
115 Correct 367 ms 25336 KB Output is correct
116 Correct 348 ms 25452 KB Output is correct