답안 #540413

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
540413 2022-03-20T10:09:47 Z Killer2501 원 고르기 (APIO18_circle_selection) C++14
100 / 100
1671 ms 34388 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<ll, int>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 3e5+5;
const int M = 350;
const ll mod = 1e9+7;
const ll inf = 2e15;
int m, t, n, tong, d[N], a[N];
int ans, res[N], b[N];
int lab[N];
ll k;
vector<pii> adj[N];
vector<pll> vi;
bool crowed[N];
ll pw(ll k, ll n)
{
    ll total =1 ;
    for(; n; n >>= 1)
    {
        if(n&1)total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}
struct circle
{
    ll x, y, r, id;
    bool operator < (const circle& c)
    {
    	return (r > c.r) || (r == c.r && id < c.id);
    }
}c[N];
bool check(int i, int j)
{
	return (c[i].x-c[j].x)*(c[i].x-c[j].x)+(c[i].y-c[j].y)*(c[i].y-c[j].y) <= (c[i].r+c[j].r)*(c[i].r+c[j].r);
}
void sol(int icase)
{
	cin >> n;
	for(int i = 1; i <= n; i ++)
	{
		cin >> c[i].x >> c[i].y >> c[i].r;
		c[i].id = i;
		c[i].x += 1e9;
		c[i].y += 1e9;
	}
	sort(c+1, c+1+n);
	int l, r = 0;
	for(int p = 30; p >= 0; p --)
	{
		ll R = (1ll<<p);
		l = r+1;
		r = 0;
		vi.clear();
		for(int i = 1; i <= n; i ++)
		{
			ll x = c[i].x >> p, y = c[i].y >> p;
			if(!r && c[i].r*2 < R)r = i-1;
			vi.pb({(x<<31ll)+y, i});
		}
		if(!r)r = n;
		sort(vi.begin(), vi.end());
        for(int i = l; i <= r; i ++)
		{
			if(res[c[i].id])continue;
			res[c[i].id] = c[i].id;
			for(ll xx = (c[i].x>>p)-2; xx <= (c[i].x>>p)+2; xx ++)
			{
				for(ll yy = (c[i].y>>p)-2; yy <= (c[i].y>>p)+2; yy ++)
				{
					k = (xx<<31ll)+yy;
					int j = lower_bound(vi.begin(), vi.end(), make_pair(k, 0)) - vi.begin();
					while(j < n && vi[j].fi == k)
					{
                        if(!res[c[vi[j].se].id] && check(i, vi[j].se))res[c[vi[j].se].id] = c[i].id;
						++j;
					}
				}
			}

		}
	}
	for(int i = 1; i <= n; i ++)cout << res[i] << " ";
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    #define task "test"
    if(fopen(task".inp", "r"))
	{
		freopen(task".inp", "r", stdin);
		freopen(task".out", "w", stdout);
	}
    int test = 1;
    //cin >> test;
    for(int i = 1; i <= test; i ++)sol(i);
    return 0;
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:100:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:101:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7380 KB Output is correct
2 Correct 5 ms 7380 KB Output is correct
3 Correct 5 ms 7380 KB Output is correct
4 Correct 5 ms 7384 KB Output is correct
5 Correct 4 ms 7384 KB Output is correct
6 Correct 6 ms 7320 KB Output is correct
7 Correct 5 ms 7464 KB Output is correct
8 Correct 4 ms 7388 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 5 ms 7380 KB Output is correct
11 Correct 5 ms 7388 KB Output is correct
12 Correct 5 ms 7388 KB Output is correct
13 Correct 4 ms 7380 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
15 Correct 4 ms 7412 KB Output is correct
16 Correct 6 ms 7396 KB Output is correct
17 Correct 7 ms 7416 KB Output is correct
18 Correct 7 ms 7380 KB Output is correct
19 Correct 20 ms 7892 KB Output is correct
20 Correct 18 ms 7928 KB Output is correct
21 Correct 18 ms 7908 KB Output is correct
22 Correct 25 ms 7904 KB Output is correct
23 Correct 24 ms 7896 KB Output is correct
24 Correct 23 ms 7908 KB Output is correct
25 Correct 22 ms 7888 KB Output is correct
26 Correct 22 ms 7892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1057 ms 26176 KB Output is correct
2 Correct 1059 ms 31796 KB Output is correct
3 Correct 1012 ms 31776 KB Output is correct
4 Correct 1039 ms 31812 KB Output is correct
5 Correct 907 ms 29652 KB Output is correct
6 Correct 1156 ms 29760 KB Output is correct
7 Correct 965 ms 29888 KB Output is correct
8 Correct 1033 ms 29708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 500 ms 15956 KB Output is correct
3 Correct 1552 ms 33304 KB Output is correct
4 Correct 1525 ms 33212 KB Output is correct
5 Correct 1388 ms 32828 KB Output is correct
6 Correct 670 ms 20868 KB Output is correct
7 Correct 344 ms 14396 KB Output is correct
8 Correct 65 ms 8944 KB Output is correct
9 Correct 1579 ms 33136 KB Output is correct
10 Correct 1402 ms 33604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1529 ms 26144 KB Output is correct
2 Correct 1368 ms 26176 KB Output is correct
3 Correct 1061 ms 26176 KB Output is correct
4 Correct 1387 ms 26180 KB Output is correct
5 Correct 1355 ms 26184 KB Output is correct
6 Correct 1008 ms 26096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7380 KB Output is correct
2 Correct 5 ms 7380 KB Output is correct
3 Correct 5 ms 7380 KB Output is correct
4 Correct 5 ms 7384 KB Output is correct
5 Correct 4 ms 7384 KB Output is correct
6 Correct 6 ms 7320 KB Output is correct
7 Correct 5 ms 7464 KB Output is correct
8 Correct 4 ms 7388 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 5 ms 7380 KB Output is correct
11 Correct 5 ms 7388 KB Output is correct
12 Correct 5 ms 7388 KB Output is correct
13 Correct 4 ms 7380 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
15 Correct 4 ms 7412 KB Output is correct
16 Correct 6 ms 7396 KB Output is correct
17 Correct 7 ms 7416 KB Output is correct
18 Correct 7 ms 7380 KB Output is correct
19 Correct 20 ms 7892 KB Output is correct
20 Correct 18 ms 7928 KB Output is correct
21 Correct 18 ms 7908 KB Output is correct
22 Correct 25 ms 7904 KB Output is correct
23 Correct 24 ms 7896 KB Output is correct
24 Correct 23 ms 7908 KB Output is correct
25 Correct 22 ms 7888 KB Output is correct
26 Correct 22 ms 7892 KB Output is correct
27 Correct 34 ms 8408 KB Output is correct
28 Correct 32 ms 8400 KB Output is correct
29 Correct 31 ms 8280 KB Output is correct
30 Correct 45 ms 8296 KB Output is correct
31 Correct 41 ms 8276 KB Output is correct
32 Correct 45 ms 8284 KB Output is correct
33 Correct 316 ms 16304 KB Output is correct
34 Correct 311 ms 16268 KB Output is correct
35 Correct 326 ms 16076 KB Output is correct
36 Correct 454 ms 15652 KB Output is correct
37 Correct 466 ms 15812 KB Output is correct
38 Correct 460 ms 15796 KB Output is correct
39 Correct 470 ms 14136 KB Output is correct
40 Correct 483 ms 14208 KB Output is correct
41 Correct 476 ms 14216 KB Output is correct
42 Correct 299 ms 14888 KB Output is correct
43 Correct 430 ms 15736 KB Output is correct
44 Correct 453 ms 15732 KB Output is correct
45 Correct 441 ms 15784 KB Output is correct
46 Correct 439 ms 15808 KB Output is correct
47 Correct 433 ms 15720 KB Output is correct
48 Correct 437 ms 15824 KB Output is correct
49 Correct 430 ms 15720 KB Output is correct
50 Correct 440 ms 15740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7380 KB Output is correct
2 Correct 5 ms 7380 KB Output is correct
3 Correct 5 ms 7380 KB Output is correct
4 Correct 5 ms 7384 KB Output is correct
5 Correct 4 ms 7384 KB Output is correct
6 Correct 6 ms 7320 KB Output is correct
7 Correct 5 ms 7464 KB Output is correct
8 Correct 4 ms 7388 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 5 ms 7380 KB Output is correct
11 Correct 5 ms 7388 KB Output is correct
12 Correct 5 ms 7388 KB Output is correct
13 Correct 4 ms 7380 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
15 Correct 4 ms 7412 KB Output is correct
16 Correct 6 ms 7396 KB Output is correct
17 Correct 7 ms 7416 KB Output is correct
18 Correct 7 ms 7380 KB Output is correct
19 Correct 20 ms 7892 KB Output is correct
20 Correct 18 ms 7928 KB Output is correct
21 Correct 18 ms 7908 KB Output is correct
22 Correct 25 ms 7904 KB Output is correct
23 Correct 24 ms 7896 KB Output is correct
24 Correct 23 ms 7908 KB Output is correct
25 Correct 22 ms 7888 KB Output is correct
26 Correct 22 ms 7892 KB Output is correct
27 Correct 1057 ms 26176 KB Output is correct
28 Correct 1059 ms 31796 KB Output is correct
29 Correct 1012 ms 31776 KB Output is correct
30 Correct 1039 ms 31812 KB Output is correct
31 Correct 907 ms 29652 KB Output is correct
32 Correct 1156 ms 29760 KB Output is correct
33 Correct 965 ms 29888 KB Output is correct
34 Correct 1033 ms 29708 KB Output is correct
35 Correct 4 ms 7380 KB Output is correct
36 Correct 500 ms 15956 KB Output is correct
37 Correct 1552 ms 33304 KB Output is correct
38 Correct 1525 ms 33212 KB Output is correct
39 Correct 1388 ms 32828 KB Output is correct
40 Correct 670 ms 20868 KB Output is correct
41 Correct 344 ms 14396 KB Output is correct
42 Correct 65 ms 8944 KB Output is correct
43 Correct 1579 ms 33136 KB Output is correct
44 Correct 1402 ms 33604 KB Output is correct
45 Correct 1529 ms 26144 KB Output is correct
46 Correct 1368 ms 26176 KB Output is correct
47 Correct 1061 ms 26176 KB Output is correct
48 Correct 1387 ms 26180 KB Output is correct
49 Correct 1355 ms 26184 KB Output is correct
50 Correct 1008 ms 26096 KB Output is correct
51 Correct 34 ms 8408 KB Output is correct
52 Correct 32 ms 8400 KB Output is correct
53 Correct 31 ms 8280 KB Output is correct
54 Correct 45 ms 8296 KB Output is correct
55 Correct 41 ms 8276 KB Output is correct
56 Correct 45 ms 8284 KB Output is correct
57 Correct 316 ms 16304 KB Output is correct
58 Correct 311 ms 16268 KB Output is correct
59 Correct 326 ms 16076 KB Output is correct
60 Correct 454 ms 15652 KB Output is correct
61 Correct 466 ms 15812 KB Output is correct
62 Correct 460 ms 15796 KB Output is correct
63 Correct 470 ms 14136 KB Output is correct
64 Correct 483 ms 14208 KB Output is correct
65 Correct 476 ms 14216 KB Output is correct
66 Correct 299 ms 14888 KB Output is correct
67 Correct 430 ms 15736 KB Output is correct
68 Correct 453 ms 15732 KB Output is correct
69 Correct 441 ms 15784 KB Output is correct
70 Correct 439 ms 15808 KB Output is correct
71 Correct 433 ms 15720 KB Output is correct
72 Correct 437 ms 15824 KB Output is correct
73 Correct 430 ms 15720 KB Output is correct
74 Correct 440 ms 15740 KB Output is correct
75 Correct 1004 ms 34388 KB Output is correct
76 Correct 1010 ms 33808 KB Output is correct
77 Correct 990 ms 34052 KB Output is correct
78 Correct 989 ms 34120 KB Output is correct
79 Correct 1080 ms 33728 KB Output is correct
80 Correct 989 ms 34220 KB Output is correct
81 Correct 1492 ms 33108 KB Output is correct
82 Correct 1485 ms 33076 KB Output is correct
83 Correct 1473 ms 32896 KB Output is correct
84 Correct 1519 ms 33468 KB Output is correct
85 Correct 1492 ms 32968 KB Output is correct
86 Correct 1481 ms 33172 KB Output is correct
87 Correct 1575 ms 33172 KB Output is correct
88 Correct 1615 ms 28480 KB Output is correct
89 Correct 1596 ms 28504 KB Output is correct
90 Correct 1653 ms 28468 KB Output is correct
91 Correct 1651 ms 28452 KB Output is correct
92 Correct 1658 ms 28568 KB Output is correct
93 Correct 1403 ms 32064 KB Output is correct
94 Correct 1462 ms 32572 KB Output is correct
95 Correct 1386 ms 31924 KB Output is correct
96 Correct 1371 ms 32060 KB Output is correct
97 Correct 1671 ms 31936 KB Output is correct
98 Correct 1187 ms 32388 KB Output is correct
99 Correct 1435 ms 32164 KB Output is correct
100 Correct 1417 ms 31884 KB Output is correct
101 Correct 1299 ms 32368 KB Output is correct
102 Correct 1382 ms 32120 KB Output is correct
103 Correct 1582 ms 32036 KB Output is correct
104 Correct 1427 ms 31812 KB Output is correct
105 Correct 1074 ms 30064 KB Output is correct
106 Correct 1387 ms 32812 KB Output is correct
107 Correct 1370 ms 32876 KB Output is correct
108 Correct 1397 ms 32848 KB Output is correct
109 Correct 1373 ms 32832 KB Output is correct
110 Correct 1367 ms 33016 KB Output is correct
111 Correct 1371 ms 32828 KB Output is correct
112 Correct 1365 ms 32832 KB Output is correct
113 Correct 1372 ms 32856 KB Output is correct
114 Correct 1423 ms 32876 KB Output is correct
115 Correct 1396 ms 32872 KB Output is correct
116 Correct 1364 ms 32820 KB Output is correct