답안 #257256

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
257256 2020-08-04T02:12:45 Z super_j6 Park (BOI16_park) C++14
100 / 100
354 ms 50860 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define f first
#define s second
#define sq(x) ((x) * (x))

const int mxn = 2000, mxm = 100000, k = 4;
int n, m, w[2];
int a[mxn][2], r[mxn];
int par[mxn + k], rnk[mxn + k];
vector<pii> v;
bool ans[mxm][k];

int fnd(int x){
	return x == par[x] ? x : par[x] = fnd(par[x]);
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	for(int i = 0; i < 2; i++) cin >> w[i];
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 2; j++) cin >> a[i][j];
		cin >> r[i];
		par[i] = i;
		
		for(int j = 0; j < i; j++){
			ll d = 0;
			for(int l = 0; l < 2; l++) d += sq((ll)a[i][l] - a[j][l]);
			v.push_back({(int)sqrtl(d) - r[i] - r[j], {j, i}});
		}
		
		for(int j = 0; j < 2; j++)
		for(int l = 0; l < 2; l++){
			v.push_back({abs(l * w[j] - a[i][j]) - r[i], {i, n + j + 2 * l}});
		}
	}
	for(int i = 0; i < k; i++) par[n + i] = n + i;
	
	for(int i = 0; i < m; i++){
		int qr, x;
		cin >> qr >> x;
		v.push_back({2 * qr, {-x, i}});
	}
	
	sort(v.begin(), v.end());
	
	for(pii i : v){
		if(i.s.f < 0){
			for(int x[2] = {-i.s.f - 1, 0}; x[1] < k; x[1]++){
				ans[i.s.s][x[1]] = 1;
				if(x[0] == x[1]) continue;
				for(int j = 0; j < 2; j++){
					int l = 1 - 2 * j;
					ans[i.s.s][x[1]] &= fnd(n + x[j]) != fnd(n + (x[j] + 1) % k);
					ans[i.s.s][x[1]] &= (k + x[1] - x[0]) % k * l < 2 * l || 
						fnd(n + (x[0] + j) % k) != fnd(n + (x[0] + j + 2) % k);
				}
			}
		}else{
			int x = fnd(i.s.f), y = fnd(i.s.s);
			if(x != y){
				if(rnk[x] < rnk[y]) swap(x, y);
				rnk[x] += rnk[x] == rnk[y];
				par[y] = x;
			}
		}
	}
	
	for(int i = 0; i < m; i++){
		string ret;
		for(int j = 0; j < k; j++) if(ans[i][j]) ret += '1' + j;
		cout << ret << endl;
	}

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 281 ms 25172 KB Output is correct
2 Correct 272 ms 25184 KB Output is correct
3 Correct 279 ms 25192 KB Output is correct
4 Correct 275 ms 25184 KB Output is correct
5 Correct 282 ms 25216 KB Output is correct
6 Correct 278 ms 25180 KB Output is correct
7 Correct 255 ms 25180 KB Output is correct
8 Correct 254 ms 25184 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 3688 KB Output is correct
2 Correct 52 ms 3692 KB Output is correct
3 Correct 51 ms 3688 KB Output is correct
4 Correct 49 ms 3688 KB Output is correct
5 Correct 52 ms 3688 KB Output is correct
6 Correct 46 ms 3688 KB Output is correct
7 Correct 51 ms 3560 KB Output is correct
8 Correct 48 ms 3560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 281 ms 25172 KB Output is correct
2 Correct 272 ms 25184 KB Output is correct
3 Correct 279 ms 25192 KB Output is correct
4 Correct 275 ms 25184 KB Output is correct
5 Correct 282 ms 25216 KB Output is correct
6 Correct 278 ms 25180 KB Output is correct
7 Correct 255 ms 25180 KB Output is correct
8 Correct 254 ms 25184 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 49 ms 3688 KB Output is correct
12 Correct 52 ms 3692 KB Output is correct
13 Correct 51 ms 3688 KB Output is correct
14 Correct 49 ms 3688 KB Output is correct
15 Correct 52 ms 3688 KB Output is correct
16 Correct 46 ms 3688 KB Output is correct
17 Correct 51 ms 3560 KB Output is correct
18 Correct 48 ms 3560 KB Output is correct
19 Correct 354 ms 50728 KB Output is correct
20 Correct 331 ms 50860 KB Output is correct
21 Correct 341 ms 50736 KB Output is correct
22 Correct 350 ms 50732 KB Output is correct
23 Correct 347 ms 50732 KB Output is correct
24 Correct 322 ms 50860 KB Output is correct