답안 #497616

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
497616 2021-12-23T11:29:16 Z jamezzz 원 고르기 (APIO18_circle_selection) C++17
100 / 100
994 ms 48980 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define dbg(...) printf(__VA_ARGS__);
#define getchar_unlocked getchar
#else
#define dbg(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
#define disc(x) sort(all(x));x.resize(unique(all(x))-x.begin());
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
mt19937 rng(time(0));

#define mod 1000000007

inline int add(int a,int b){
	int r=a+b;
	while(r>=mod)r-=mod;
	while(r<0)r+=mod;
	return r;
}

inline int mult(int a,int b){
	return (int)(((ll)(a*b))%mod);
}

inline int rd(){
    int x=0;
    char ch=getchar_unlocked();
    while(ch<'0'||ch>'9')ch=getchar_unlocked();
    while(ch>='0'&&ch<='9'){
		x=(x<<3)+(x<<1)+ch-'0';
		ch=getchar_unlocked();
	}
    return x;
}

#define maxn 300005

struct circle{
	ll x,y,r,i;
}a[maxn];

bool cmp(circle &a,circle &b){
	if(a.r==b.r)return a.i<b.i;
	return a.r>b.r;
}

bool intersect(circle &i,circle &j){
	return (i.x-j.x)*(i.x-j.x)+(i.y-j.y)*(i.y-j.y)<=(i.r+j.r)*(i.r+j.r);
}

int n;ll x,y,r,ans[maxn];
bool used[maxn];
ll gridsz;
unordered_map<ll,vector<int>> grid;

ll hh(ll x,ll y){
	return x*(1ll<<32)+y;
}

void build(){
	grid.clear();
	for(int i=1;i<=n;++i){
		if(used[i])continue;
		ll x=a[i].x/gridsz;
		ll y=a[i].y/gridsz;
		grid[hh(x,y)].pb(i);
	}
}

int main(){
	sf("%d",&n);
	for(int i=1;i<=n;++i){
		sf("%lld%lld%lld",&x,&y,&r);
		x+=(1ll<<30);y+=(1ll<<30);
		a[i]={x,y,r,i};
		mxto(gridsz,r);
	}
	sort(a+1,a+n+1,cmp);
	build();
	for(int i=1;i<=n;++i){
		if(used[i])continue;
		if(gridsz>2*a[i].r){
			gridsz=a[i].r;
			build();
		}
		ll x=a[i].x/gridsz;
		ll y=a[i].y/gridsz;
		for(ll nx=x-2;nx<=x+2;++nx){
			for(ll ny=y-2;ny<=y+2;++ny){
				if(grid.find(hh(nx,ny))==grid.end())continue;
				vector<int> tmp;
				vector<int> &pts=grid[hh(nx,ny)];
				for(int p:pts){
					if(intersect(a[i],a[p])){
						used[p]=true;
						ans[a[p].i]=a[i].i;
					}
					else tmp.pb(p);
				}
				swap(grid[hh(nx,ny)],tmp);
			}
		}
	}
	for(int i=1;i<=n;++i)pf("%d ",ans[i]);
	pf("\n");
}

/*
11
9 9 2
13 2 1
11 8 2
3 3 2
3 12 1
12 14 1
9 8 5
2 8 2
5 2 1
14 4 2
14 14 1
*/

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:123:28: warning: format '%d' expects argument of type 'int', but argument 2 has type 'll' {aka 'long long int'} [-Wformat=]
  123 |  for(int i=1;i<=n;++i)pf("%d ",ans[i]);
      |                           ~^   ~~~~~~
      |                            |        |
      |                            int      ll {aka long long int}
      |                           %lld
circle_selection.cpp:90:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |  sf("%d",&n);
      |    ^
circle_selection.cpp:92:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |   sf("%lld%lld%lld",&x,&y,&r);
      |     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 308 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 308 KB Output is correct
6 Correct 0 ms 296 KB Output is correct
7 Correct 0 ms 336 KB Output is correct
8 Correct 0 ms 304 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 0 ms 308 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 3 ms 720 KB Output is correct
20 Correct 4 ms 628 KB Output is correct
21 Correct 3 ms 700 KB Output is correct
22 Correct 8 ms 1104 KB Output is correct
23 Correct 9 ms 1080 KB Output is correct
24 Correct 8 ms 1104 KB Output is correct
25 Correct 8 ms 1092 KB Output is correct
26 Correct 8 ms 1104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 165 ms 21408 KB Output is correct
2 Correct 171 ms 21240 KB Output is correct
3 Correct 169 ms 21388 KB Output is correct
4 Correct 168 ms 21788 KB Output is correct
5 Correct 198 ms 21364 KB Output is correct
6 Correct 412 ms 31864 KB Output is correct
7 Correct 219 ms 22724 KB Output is correct
8 Correct 257 ms 24692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 187 ms 16800 KB Output is correct
3 Correct 832 ms 48588 KB Output is correct
4 Correct 848 ms 48668 KB Output is correct
5 Correct 778 ms 43816 KB Output is correct
6 Correct 265 ms 22328 KB Output is correct
7 Correct 112 ms 11920 KB Output is correct
8 Correct 19 ms 2776 KB Output is correct
9 Correct 905 ms 47976 KB Output is correct
10 Correct 680 ms 43384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 761 ms 48496 KB Output is correct
2 Correct 784 ms 47716 KB Output is correct
3 Correct 293 ms 31032 KB Output is correct
4 Correct 771 ms 47976 KB Output is correct
5 Correct 790 ms 48152 KB Output is correct
6 Correct 222 ms 25820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 308 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 308 KB Output is correct
6 Correct 0 ms 296 KB Output is correct
7 Correct 0 ms 336 KB Output is correct
8 Correct 0 ms 304 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 0 ms 308 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 3 ms 720 KB Output is correct
20 Correct 4 ms 628 KB Output is correct
21 Correct 3 ms 700 KB Output is correct
22 Correct 8 ms 1104 KB Output is correct
23 Correct 9 ms 1080 KB Output is correct
24 Correct 8 ms 1104 KB Output is correct
25 Correct 8 ms 1092 KB Output is correct
26 Correct 8 ms 1104 KB Output is correct
27 Correct 6 ms 1104 KB Output is correct
28 Correct 5 ms 1104 KB Output is correct
29 Correct 6 ms 1104 KB Output is correct
30 Correct 17 ms 1836 KB Output is correct
31 Correct 15 ms 1872 KB Output is correct
32 Correct 17 ms 1856 KB Output is correct
33 Correct 55 ms 8168 KB Output is correct
34 Correct 54 ms 8076 KB Output is correct
35 Correct 60 ms 8000 KB Output is correct
36 Correct 170 ms 16572 KB Output is correct
37 Correct 176 ms 16644 KB Output is correct
38 Correct 183 ms 16700 KB Output is correct
39 Correct 246 ms 13988 KB Output is correct
40 Correct 246 ms 13980 KB Output is correct
41 Correct 239 ms 13896 KB Output is correct
42 Correct 146 ms 15764 KB Output is correct
43 Correct 178 ms 16572 KB Output is correct
44 Correct 161 ms 16452 KB Output is correct
45 Correct 169 ms 16512 KB Output is correct
46 Correct 177 ms 16556 KB Output is correct
47 Correct 170 ms 16444 KB Output is correct
48 Correct 179 ms 16492 KB Output is correct
49 Correct 190 ms 16424 KB Output is correct
50 Correct 168 ms 16552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 308 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 308 KB Output is correct
6 Correct 0 ms 296 KB Output is correct
7 Correct 0 ms 336 KB Output is correct
8 Correct 0 ms 304 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 0 ms 308 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 3 ms 720 KB Output is correct
20 Correct 4 ms 628 KB Output is correct
21 Correct 3 ms 700 KB Output is correct
22 Correct 8 ms 1104 KB Output is correct
23 Correct 9 ms 1080 KB Output is correct
24 Correct 8 ms 1104 KB Output is correct
25 Correct 8 ms 1092 KB Output is correct
26 Correct 8 ms 1104 KB Output is correct
27 Correct 165 ms 21408 KB Output is correct
28 Correct 171 ms 21240 KB Output is correct
29 Correct 169 ms 21388 KB Output is correct
30 Correct 168 ms 21788 KB Output is correct
31 Correct 198 ms 21364 KB Output is correct
32 Correct 412 ms 31864 KB Output is correct
33 Correct 219 ms 22724 KB Output is correct
34 Correct 257 ms 24692 KB Output is correct
35 Correct 1 ms 208 KB Output is correct
36 Correct 187 ms 16800 KB Output is correct
37 Correct 832 ms 48588 KB Output is correct
38 Correct 848 ms 48668 KB Output is correct
39 Correct 778 ms 43816 KB Output is correct
40 Correct 265 ms 22328 KB Output is correct
41 Correct 112 ms 11920 KB Output is correct
42 Correct 19 ms 2776 KB Output is correct
43 Correct 905 ms 47976 KB Output is correct
44 Correct 680 ms 43384 KB Output is correct
45 Correct 761 ms 48496 KB Output is correct
46 Correct 784 ms 47716 KB Output is correct
47 Correct 293 ms 31032 KB Output is correct
48 Correct 771 ms 47976 KB Output is correct
49 Correct 790 ms 48152 KB Output is correct
50 Correct 222 ms 25820 KB Output is correct
51 Correct 6 ms 1104 KB Output is correct
52 Correct 5 ms 1104 KB Output is correct
53 Correct 6 ms 1104 KB Output is correct
54 Correct 17 ms 1836 KB Output is correct
55 Correct 15 ms 1872 KB Output is correct
56 Correct 17 ms 1856 KB Output is correct
57 Correct 55 ms 8168 KB Output is correct
58 Correct 54 ms 8076 KB Output is correct
59 Correct 60 ms 8000 KB Output is correct
60 Correct 170 ms 16572 KB Output is correct
61 Correct 176 ms 16644 KB Output is correct
62 Correct 183 ms 16700 KB Output is correct
63 Correct 246 ms 13988 KB Output is correct
64 Correct 246 ms 13980 KB Output is correct
65 Correct 239 ms 13896 KB Output is correct
66 Correct 146 ms 15764 KB Output is correct
67 Correct 178 ms 16572 KB Output is correct
68 Correct 161 ms 16452 KB Output is correct
69 Correct 169 ms 16512 KB Output is correct
70 Correct 177 ms 16556 KB Output is correct
71 Correct 170 ms 16444 KB Output is correct
72 Correct 179 ms 16492 KB Output is correct
73 Correct 190 ms 16424 KB Output is correct
74 Correct 168 ms 16552 KB Output is correct
75 Correct 200 ms 24084 KB Output is correct
76 Correct 172 ms 23396 KB Output is correct
77 Correct 170 ms 24152 KB Output is correct
78 Correct 168 ms 23388 KB Output is correct
79 Correct 218 ms 23312 KB Output is correct
80 Correct 185 ms 23840 KB Output is correct
81 Correct 855 ms 48520 KB Output is correct
82 Correct 854 ms 48364 KB Output is correct
83 Correct 865 ms 48280 KB Output is correct
84 Correct 994 ms 48980 KB Output is correct
85 Correct 832 ms 48376 KB Output is correct
86 Correct 858 ms 48752 KB Output is correct
87 Correct 827 ms 48408 KB Output is correct
88 Correct 886 ms 40504 KB Output is correct
89 Correct 880 ms 40340 KB Output is correct
90 Correct 875 ms 40432 KB Output is correct
91 Correct 878 ms 40484 KB Output is correct
92 Correct 890 ms 40340 KB Output is correct
93 Correct 844 ms 47592 KB Output is correct
94 Correct 835 ms 47676 KB Output is correct
95 Correct 862 ms 47388 KB Output is correct
96 Correct 837 ms 47472 KB Output is correct
97 Correct 847 ms 47308 KB Output is correct
98 Correct 545 ms 39596 KB Output is correct
99 Correct 840 ms 47692 KB Output is correct
100 Correct 796 ms 47388 KB Output is correct
101 Correct 736 ms 42780 KB Output is correct
102 Correct 798 ms 47080 KB Output is correct
103 Correct 849 ms 47172 KB Output is correct
104 Correct 846 ms 47360 KB Output is correct
105 Correct 604 ms 45212 KB Output is correct
106 Correct 663 ms 46756 KB Output is correct
107 Correct 658 ms 46736 KB Output is correct
108 Correct 681 ms 46872 KB Output is correct
109 Correct 684 ms 46828 KB Output is correct
110 Correct 669 ms 46796 KB Output is correct
111 Correct 676 ms 46816 KB Output is correct
112 Correct 651 ms 46832 KB Output is correct
113 Correct 671 ms 46768 KB Output is correct
114 Correct 679 ms 46716 KB Output is correct
115 Correct 672 ms 46712 KB Output is correct
116 Correct 668 ms 46808 KB Output is correct