Submission #948060

# Submission time Handle Problem Language Result Execution time Memory
948060 2024-03-17T14:33:30 Z koukirocks Park (BOI16_park) C++17
27 / 100
221 ms 35528 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;
	int a,b;
	edge(int _a,int _b,int _w):a(_a),b(_b),w(_w){}
};

struct query{
	int 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;
						break;
					}
				}
			}
			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(int, int, int)':
park.cpp:26:8: warning: 'edge::b' will be initialized after [-Wreorder]
   26 |  int 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(int _a,int _b,int _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) {
      |          ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 219 ms 33604 KB Output is correct
2 Correct 220 ms 34164 KB Output is correct
3 Correct 206 ms 33804 KB Output is correct
4 Correct 210 ms 35528 KB Output is correct
5 Correct 221 ms 33720 KB Output is correct
6 Correct 218 ms 35012 KB Output is correct
7 Correct 204 ms 34504 KB Output is correct
8 Correct 188 ms 35016 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 3532 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 219 ms 33604 KB Output is correct
2 Correct 220 ms 34164 KB Output is correct
3 Correct 206 ms 33804 KB Output is correct
4 Correct 210 ms 35528 KB Output is correct
5 Correct 221 ms 33720 KB Output is correct
6 Correct 218 ms 35012 KB Output is correct
7 Correct 204 ms 34504 KB Output is correct
8 Correct 188 ms 35016 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Incorrect 32 ms 3532 KB Output isn't correct
12 Halted 0 ms 0 KB -