답안 #948069

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
948069 2024-03-17T14:41:57 Z koukirocks Park (BOI16_park) C++17
100 / 100
303 ms 55024 KB
#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
 
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const ll MAX=2e3+10,P=998244353;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;

int n,m;
ll w,h;

struct circle{
	ll x,y,r;
}tree[MAX];

struct edge{
	db w;
	ll a,b;
	edge(ll _a,ll _b,db _w):a(_a),b(_b),w(_w){}
};

struct query{
	ll r,x,id;
}q[MAX*50];

int fa[MAX];

void init() {
	for (int i=1;i<=n+4;i++) {
		fa[i]=i;
	}
}

int get(int a) {
	return fa[a]=(fa[a]==a?a:get(fa[a]));
}

void unionn(int a,int b) {
	a=get(a);
	b=get(b);
	if (a==b) return;
	fa[a]=b;
}

int main() {
	speed;
	cin>>n>>m;
	cin>>w>>h;
	for (int i=1;i<=n;i++) {
		cin>>tree[i].x>>tree[i].y>>tree[i].r;
	}
	for (int i=1;i<=m;i++) {
		cin>>q[i].r>>q[i].x;
		q[i].id=i;
	}
	sort(q+1,q+m+1,[&](query a,query b) {
		return a.r<b.r;
	});
	vector<edge> egs;
	for (int i=1;i<=n;i++) {
		for (int j=i+1;j<=n;j++) {
			ll dx=tree[i].x-tree[j].x;
			ll dy=tree[i].y-tree[j].y;
			egs.emplace_back(i,j,sqrt(dx*dx+dy*dy)-tree[i].r-tree[j].r);
		}
	}
	for (int i=1;i<=n;i++) {
		egs.emplace_back(i,n+1,tree[i].y-tree[i].r);
		egs.emplace_back(i,n+2,w-tree[i].x-tree[i].r);
		egs.emplace_back(i,n+3,h-tree[i].y-tree[i].r);
		egs.emplace_back(i,n+4,tree[i].x-tree[i].r);
	}
	sort(all(egs),[&](edge a,edge b){
		return a.w<b.w;
	});
	vector<int> ans(m+1);
	init();
	int id=0;
	for (int i=1;i<=m;i++) {
		while (id<egs.size() and egs[id].w<2*q[i].r) {
			unionn(egs[id].a,egs[id].b);
			id++;
//			cout<<id<<" id\n";
		}
		ans[q[i].id]=0;
		for (int ex=1;ex<=4;ex++) {
//			cout<<ex<<" :\n";
			if (ex==q[i].x) {
				ans[q[i].id]+=(1<<ex);
				continue;
			}
			bool cross=false;
			for (int a=ex;a!=q[i].x;a=a%4+1) {
				for (int b=q[i].x;b!=ex;b=b%4+1) {
//					cout<<q[i].r<<" "<<a<<" "<<b<<" "<<(get(n+a)==get(n+b))<<"\n";
					if (get(n+a)==get(n+b)) {
						cross=true;
					}
				}
			}
			if (!cross) ans[q[i].id]+=(1<<ex);
		}
	}
	for (int i=1;i<=m;i++) {
		for (int j=1;j<=4;j++) {
			if (ans[i]&(1<<j)) cout<<j;
		}
		cout<<"\n";
	}
	return 0;
}
/*
5 3
16 11
11 8 1
6 10 1
7 3 2
10 4 1
15 5 1
1 1
2 2
2 1
*/

Compilation message

park.cpp: In constructor 'edge::edge(ll, ll, db)':
park.cpp:26:7: warning: 'edge::b' will be initialized after [-Wreorder]
   26 |  ll a,b;
      |       ^
park.cpp:25:5: warning:   'db edge::w' [-Wreorder]
   25 |  db w;
      |     ^
park.cpp:27:2: warning:   when initialized here [-Wreorder]
   27 |  edge(ll _a,ll _b,db _w):a(_a),b(_b),w(_w){}
      |  ^~~~
park.cpp: In function 'int main()':
park.cpp:88:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |   while (id<egs.size() and egs[id].w<2*q[i].r) {
      |          ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 226 ms 51116 KB Output is correct
2 Correct 230 ms 50860 KB Output is correct
3 Correct 223 ms 50876 KB Output is correct
4 Correct 219 ms 50880 KB Output is correct
5 Correct 216 ms 50364 KB Output is correct
6 Correct 227 ms 50992 KB Output is correct
7 Correct 208 ms 50876 KB Output is correct
8 Correct 206 ms 50112 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 4168 KB Output is correct
2 Correct 38 ms 5068 KB Output is correct
3 Correct 45 ms 5144 KB Output is correct
4 Correct 40 ms 5224 KB Output is correct
5 Correct 35 ms 5060 KB Output is correct
6 Correct 37 ms 5208 KB Output is correct
7 Correct 31 ms 4500 KB Output is correct
8 Correct 33 ms 4504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 226 ms 51116 KB Output is correct
2 Correct 230 ms 50860 KB Output is correct
3 Correct 223 ms 50876 KB Output is correct
4 Correct 219 ms 50880 KB Output is correct
5 Correct 216 ms 50364 KB Output is correct
6 Correct 227 ms 50992 KB Output is correct
7 Correct 208 ms 50876 KB Output is correct
8 Correct 206 ms 50112 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 52 ms 4168 KB Output is correct
12 Correct 38 ms 5068 KB Output is correct
13 Correct 45 ms 5144 KB Output is correct
14 Correct 40 ms 5224 KB Output is correct
15 Correct 35 ms 5060 KB Output is correct
16 Correct 37 ms 5208 KB Output is correct
17 Correct 31 ms 4500 KB Output is correct
18 Correct 33 ms 4504 KB Output is correct
19 Correct 257 ms 54464 KB Output is correct
20 Correct 253 ms 54708 KB Output is correct
21 Correct 261 ms 53376 KB Output is correct
22 Correct 253 ms 54964 KB Output is correct
23 Correct 253 ms 55024 KB Output is correct
24 Correct 303 ms 54708 KB Output is correct