답안 #64376

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
64376 2018-08-04T09:07:53 Z zscoder 원 고르기 (APIO18_circle_selection) C++17
100 / 100
2671 ms 387520 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

struct circle
{
	int x,y,r,id;
	circle(int _x, int _y, int _r, int _id){x=_x;y=_y;r=_r;id=_id;}
};

bool operator<(circle a, circle b)
{
	if(a.r!=b.r) return a.r<b.r;
	else return a.id>b.id;
}

bool cmp(circle a, circle b)
{
	if(a.y!=b.y) return a.y<b.y;
	else return a.id>b.id;
}
vector<circle> a;
int ans[333333];
vector<circle> vec;

vector<pair<int,int> > V[333333];
vi xs;
vector<circle> v2;

void init(int R)
{
	xs.clear();
	for(int i=0;i<vec.size();i++)
	{
		if(!ans[vec[i].id])
		{
			xs.pb(vec[i].x/R);
		}
	}
	sort(xs.begin(),xs.end()); xs.erase(unique(xs.begin(),xs.end()),xs.end());
	for(int i=0;i<xs.size();i++) V[i].clear();
	for(int i=0;i<v2.size();i++)
	{
		if(!ans[v2[i].id])
		{
			V[lower_bound(xs.begin(),xs.end(),v2[i].x/R)-xs.begin()].pb(mp(v2[i].y/R, v2[i].id));
		}
	}
}

bool intersect(circle x, circle y)
{
	ll d = (x.x-y.x)*1LL*(x.x-y.x) + (x.y-y.y)*1LL*(x.y-y.y);
	return (d<=(x.r+y.r)*1LL*(x.r+y.r));
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n;i++)
	{
		int x,y,r; cin>>x>>y>>r;
		vec.pb(circle(x,y,r,i+1));
	}
	a=vec; v2=vec;
	sort(v2.begin(),v2.end(),cmp);
	sort(vec.rbegin(),vec.rend());
	int curC = int(1e9); init(curC);
	for(int i=0;i<vec.size();i++)
	{
		if(ans[vec[i].id]) continue;
		while(vec[i].r*2<=curC)
		{
			curC/=2; init(curC);
		}
		int x=vec[i].x/curC;
		x=lower_bound(xs.begin(),xs.end(),x)-xs.begin();
		for(int dx=-2;dx<=2;dx++)
		{
			if(x+dx>=0&&x+dx<xs.size()&&abs(xs[x]-xs[x+dx])<=2)
			{
				auto it = lower_bound(V[x+dx].begin(),V[x+dx].end(),mp(vec[i].y/curC - 2, -1));
				for(;it!=V[x+dx].end()&&it->fi<=vec[i].y/curC + 2;it++)
				{
					if(ans[it->se]){continue;}
					if(intersect(a[it->se-1], vec[i]))
					{
						ans[it->se] = vec[i].id; 
					}
				} 
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		cout<<ans[i];
		if(i+1<=n) cout<<' ';
	}
	cout<<'\n';
}

Compilation message

circle_selection.cpp: In function 'void init(int)':
circle_selection.cpp:47:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<vec.size();i++)
              ~^~~~~~~~~~~
circle_selection.cpp:55:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<xs.size();i++) V[i].clear();
              ~^~~~~~~~~~
circle_selection.cpp:56:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<v2.size();i++)
              ~^~~~~~~~~~
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:84:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<vec.size();i++)
              ~^~~~~~~~~~~
circle_selection.cpp:95:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(x+dx>=0&&x+dx<xs.size()&&abs(xs[x]-xs[x+dx])<=2)
                ~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8184 KB Output is correct
2 Correct 8 ms 8292 KB Output is correct
3 Correct 9 ms 8376 KB Output is correct
4 Correct 9 ms 8376 KB Output is correct
5 Correct 8 ms 8376 KB Output is correct
6 Correct 8 ms 8376 KB Output is correct
7 Correct 9 ms 8416 KB Output is correct
8 Correct 10 ms 8500 KB Output is correct
9 Correct 8 ms 8500 KB Output is correct
10 Correct 9 ms 8500 KB Output is correct
11 Correct 11 ms 8500 KB Output is correct
12 Correct 10 ms 8500 KB Output is correct
13 Correct 10 ms 8500 KB Output is correct
14 Correct 9 ms 8500 KB Output is correct
15 Correct 11 ms 8500 KB Output is correct
16 Correct 12 ms 8500 KB Output is correct
17 Correct 13 ms 8520 KB Output is correct
18 Correct 12 ms 8532 KB Output is correct
19 Correct 15 ms 8812 KB Output is correct
20 Correct 18 ms 8812 KB Output is correct
21 Correct 15 ms 8820 KB Output is correct
22 Correct 28 ms 9124 KB Output is correct
23 Correct 23 ms 9124 KB Output is correct
24 Correct 29 ms 9212 KB Output is correct
25 Correct 31 ms 9244 KB Output is correct
26 Correct 29 ms 9244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 317 ms 33516 KB Output is correct
2 Correct 300 ms 33516 KB Output is correct
3 Correct 321 ms 33516 KB Output is correct
4 Correct 274 ms 33516 KB Output is correct
5 Correct 947 ms 49084 KB Output is correct
6 Correct 1489 ms 60688 KB Output is correct
7 Correct 1076 ms 60688 KB Output is correct
8 Correct 1217 ms 60688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 60688 KB Output is correct
2 Correct 399 ms 60688 KB Output is correct
3 Correct 1286 ms 60688 KB Output is correct
4 Correct 1588 ms 60688 KB Output is correct
5 Correct 1111 ms 60688 KB Output is correct
6 Correct 475 ms 60688 KB Output is correct
7 Correct 296 ms 60688 KB Output is correct
8 Correct 60 ms 60688 KB Output is correct
9 Correct 1384 ms 60688 KB Output is correct
10 Correct 1110 ms 60688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1341 ms 60688 KB Output is correct
2 Correct 2520 ms 61084 KB Output is correct
3 Correct 647 ms 61084 KB Output is correct
4 Correct 1997 ms 75784 KB Output is correct
5 Correct 1959 ms 88832 KB Output is correct
6 Correct 539 ms 88832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8184 KB Output is correct
2 Correct 8 ms 8292 KB Output is correct
3 Correct 9 ms 8376 KB Output is correct
4 Correct 9 ms 8376 KB Output is correct
5 Correct 8 ms 8376 KB Output is correct
6 Correct 8 ms 8376 KB Output is correct
7 Correct 9 ms 8416 KB Output is correct
8 Correct 10 ms 8500 KB Output is correct
9 Correct 8 ms 8500 KB Output is correct
10 Correct 9 ms 8500 KB Output is correct
11 Correct 11 ms 8500 KB Output is correct
12 Correct 10 ms 8500 KB Output is correct
13 Correct 10 ms 8500 KB Output is correct
14 Correct 9 ms 8500 KB Output is correct
15 Correct 11 ms 8500 KB Output is correct
16 Correct 12 ms 8500 KB Output is correct
17 Correct 13 ms 8520 KB Output is correct
18 Correct 12 ms 8532 KB Output is correct
19 Correct 15 ms 8812 KB Output is correct
20 Correct 18 ms 8812 KB Output is correct
21 Correct 15 ms 8820 KB Output is correct
22 Correct 28 ms 9124 KB Output is correct
23 Correct 23 ms 9124 KB Output is correct
24 Correct 29 ms 9212 KB Output is correct
25 Correct 31 ms 9244 KB Output is correct
26 Correct 29 ms 9244 KB Output is correct
27 Correct 24 ms 88832 KB Output is correct
28 Correct 20 ms 88832 KB Output is correct
29 Correct 21 ms 88832 KB Output is correct
30 Correct 42 ms 88832 KB Output is correct
31 Correct 46 ms 88832 KB Output is correct
32 Correct 50 ms 88832 KB Output is correct
33 Correct 108 ms 88832 KB Output is correct
34 Correct 97 ms 88832 KB Output is correct
35 Correct 142 ms 88832 KB Output is correct
36 Correct 480 ms 88832 KB Output is correct
37 Correct 503 ms 88832 KB Output is correct
38 Correct 450 ms 88832 KB Output is correct
39 Correct 469 ms 88832 KB Output is correct
40 Correct 372 ms 88832 KB Output is correct
41 Correct 408 ms 88832 KB Output is correct
42 Correct 251 ms 88832 KB Output is correct
43 Correct 402 ms 88832 KB Output is correct
44 Correct 394 ms 88832 KB Output is correct
45 Correct 362 ms 88832 KB Output is correct
46 Correct 368 ms 88832 KB Output is correct
47 Correct 430 ms 88832 KB Output is correct
48 Correct 365 ms 88832 KB Output is correct
49 Correct 467 ms 88832 KB Output is correct
50 Correct 414 ms 88832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8184 KB Output is correct
2 Correct 8 ms 8292 KB Output is correct
3 Correct 9 ms 8376 KB Output is correct
4 Correct 9 ms 8376 KB Output is correct
5 Correct 8 ms 8376 KB Output is correct
6 Correct 8 ms 8376 KB Output is correct
7 Correct 9 ms 8416 KB Output is correct
8 Correct 10 ms 8500 KB Output is correct
9 Correct 8 ms 8500 KB Output is correct
10 Correct 9 ms 8500 KB Output is correct
11 Correct 11 ms 8500 KB Output is correct
12 Correct 10 ms 8500 KB Output is correct
13 Correct 10 ms 8500 KB Output is correct
14 Correct 9 ms 8500 KB Output is correct
15 Correct 11 ms 8500 KB Output is correct
16 Correct 12 ms 8500 KB Output is correct
17 Correct 13 ms 8520 KB Output is correct
18 Correct 12 ms 8532 KB Output is correct
19 Correct 15 ms 8812 KB Output is correct
20 Correct 18 ms 8812 KB Output is correct
21 Correct 15 ms 8820 KB Output is correct
22 Correct 28 ms 9124 KB Output is correct
23 Correct 23 ms 9124 KB Output is correct
24 Correct 29 ms 9212 KB Output is correct
25 Correct 31 ms 9244 KB Output is correct
26 Correct 29 ms 9244 KB Output is correct
27 Correct 317 ms 33516 KB Output is correct
28 Correct 300 ms 33516 KB Output is correct
29 Correct 321 ms 33516 KB Output is correct
30 Correct 274 ms 33516 KB Output is correct
31 Correct 947 ms 49084 KB Output is correct
32 Correct 1489 ms 60688 KB Output is correct
33 Correct 1076 ms 60688 KB Output is correct
34 Correct 1217 ms 60688 KB Output is correct
35 Correct 11 ms 60688 KB Output is correct
36 Correct 399 ms 60688 KB Output is correct
37 Correct 1286 ms 60688 KB Output is correct
38 Correct 1588 ms 60688 KB Output is correct
39 Correct 1111 ms 60688 KB Output is correct
40 Correct 475 ms 60688 KB Output is correct
41 Correct 296 ms 60688 KB Output is correct
42 Correct 60 ms 60688 KB Output is correct
43 Correct 1384 ms 60688 KB Output is correct
44 Correct 1110 ms 60688 KB Output is correct
45 Correct 1341 ms 60688 KB Output is correct
46 Correct 2520 ms 61084 KB Output is correct
47 Correct 647 ms 61084 KB Output is correct
48 Correct 1997 ms 75784 KB Output is correct
49 Correct 1959 ms 88832 KB Output is correct
50 Correct 539 ms 88832 KB Output is correct
51 Correct 24 ms 88832 KB Output is correct
52 Correct 20 ms 88832 KB Output is correct
53 Correct 21 ms 88832 KB Output is correct
54 Correct 42 ms 88832 KB Output is correct
55 Correct 46 ms 88832 KB Output is correct
56 Correct 50 ms 88832 KB Output is correct
57 Correct 108 ms 88832 KB Output is correct
58 Correct 97 ms 88832 KB Output is correct
59 Correct 142 ms 88832 KB Output is correct
60 Correct 480 ms 88832 KB Output is correct
61 Correct 503 ms 88832 KB Output is correct
62 Correct 450 ms 88832 KB Output is correct
63 Correct 469 ms 88832 KB Output is correct
64 Correct 372 ms 88832 KB Output is correct
65 Correct 408 ms 88832 KB Output is correct
66 Correct 251 ms 88832 KB Output is correct
67 Correct 402 ms 88832 KB Output is correct
68 Correct 394 ms 88832 KB Output is correct
69 Correct 362 ms 88832 KB Output is correct
70 Correct 368 ms 88832 KB Output is correct
71 Correct 430 ms 88832 KB Output is correct
72 Correct 365 ms 88832 KB Output is correct
73 Correct 467 ms 88832 KB Output is correct
74 Correct 414 ms 88832 KB Output is correct
75 Correct 482 ms 88832 KB Output is correct
76 Correct 438 ms 88832 KB Output is correct
77 Correct 390 ms 92388 KB Output is correct
78 Correct 305 ms 101116 KB Output is correct
79 Correct 572 ms 110808 KB Output is correct
80 Correct 336 ms 118920 KB Output is correct
81 Correct 1546 ms 149808 KB Output is correct
82 Correct 1522 ms 155732 KB Output is correct
83 Correct 1643 ms 168952 KB Output is correct
84 Correct 1284 ms 172720 KB Output is correct
85 Correct 1318 ms 182868 KB Output is correct
86 Correct 1431 ms 189752 KB Output is correct
87 Correct 1151 ms 189752 KB Output is correct
88 Correct 1621 ms 193276 KB Output is correct
89 Correct 1272 ms 195864 KB Output is correct
90 Correct 1445 ms 199492 KB Output is correct
91 Correct 1579 ms 202420 KB Output is correct
92 Correct 1540 ms 206320 KB Output is correct
93 Correct 2464 ms 231324 KB Output is correct
94 Correct 1026 ms 231324 KB Output is correct
95 Correct 2442 ms 241688 KB Output is correct
96 Correct 2237 ms 251452 KB Output is correct
97 Correct 964 ms 251452 KB Output is correct
98 Correct 1458 ms 257376 KB Output is correct
99 Correct 2385 ms 271768 KB Output is correct
100 Correct 2671 ms 274524 KB Output is correct
101 Correct 1362 ms 274524 KB Output is correct
102 Correct 2188 ms 287456 KB Output is correct
103 Correct 888 ms 287456 KB Output is correct
104 Correct 2333 ms 301940 KB Output is correct
105 Correct 751 ms 301940 KB Output is correct
106 Correct 1068 ms 313236 KB Output is correct
107 Correct 1039 ms 320732 KB Output is correct
108 Correct 1054 ms 327780 KB Output is correct
109 Correct 1122 ms 334728 KB Output is correct
110 Correct 1078 ms 342632 KB Output is correct
111 Correct 1081 ms 348976 KB Output is correct
112 Correct 1066 ms 355808 KB Output is correct
113 Correct 1000 ms 364032 KB Output is correct
114 Correct 1074 ms 371088 KB Output is correct
115 Correct 1115 ms 378628 KB Output is correct
116 Correct 1178 ms 387520 KB Output is correct