답안 #948064

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
948064 2024-03-17T14:39:01 Z koukirocks Park (BOI16_park) C++17
27 / 100
230 ms 51924 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[i]=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 229 ms 51924 KB Output is correct
2 Correct 220 ms 51136 KB Output is correct
3 Correct 225 ms 50368 KB Output is correct
4 Correct 226 ms 51820 KB Output is correct
5 Correct 225 ms 50368 KB Output is correct
6 Correct 230 ms 50708 KB Output is correct
7 Correct 212 ms 50624 KB Output is correct
8 Correct 202 ms 50368 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 36 ms 3964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 229 ms 51924 KB Output is correct
2 Correct 220 ms 51136 KB Output is correct
3 Correct 225 ms 50368 KB Output is correct
4 Correct 226 ms 51820 KB Output is correct
5 Correct 225 ms 50368 KB Output is correct
6 Correct 230 ms 50708 KB Output is correct
7 Correct 212 ms 50624 KB Output is correct
8 Correct 202 ms 50368 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Incorrect 36 ms 3964 KB Output isn't correct
12 Halted 0 ms 0 KB -