답안 #698829

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
698829 2023-02-14T10:52:25 Z ono_de206 Park (BOI16_park) C++14
100 / 100
334 ms 56476 KB
#include<bits/stdc++.h>
using namespace std;
 
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define PP make_pair

#define int long long
 
typedef long long ll;

typedef pair<int, int> P;
typedef pair<P, P> L;

template<typename T>
void mxx(T &a, T b){if(b > a) a = b;}
template<typename T>
void mnn(T &a, T b){if(b < a) a = b;}

const int mxn = 2010;
const int mxm = 1e5 + 10;
const int inf = 1e18 + 10;

array<int, 3> a[mxn], b[mxm];
vector<array<int, 3>> g;
array<int, 4> mm[mxn];
int is[10][10];
string ans[mxm];
int h, w, now, par[mxn];

int dis(int x1, int y1, int x2, int y2) {
	return (int)(sqrt(double((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))) * 1e6);
}

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

void untie(int x, int y) {
	x = get(x); y = get(y);
	if(x == y) return;
	par[y] = x;
	mnn(mm[x][0], mm[y][0]);
	mnn(mm[x][1], mm[y][1]);
	mnn(mm[x][2], mm[y][2]);
	mnn(mm[x][3], mm[y][3]);
	for(int i = 0; i < 4; i++) {
		for(int j = 0; j < 4; j++) {
			mnn(is[i][j], max(mm[x][i], mm[x][j]) * (int)1e6);			
		}
	}
}

string getAns(int x) {
	string ans = "";
	for(int i = 1; i <= 4; i++) {
		if(x == i) {
			ans.pb(i + '0');
			continue;
		}
		if(x == 1) {
			// cout << is[x - 1][(x - 2 + 4) % 4] / (int)1e6 << ' ' << is[i - 1][(i - 2 + 4) % 4] / (int)1e6 << ' ' << now / (int)1e6 << '\n';
		}
		if(is[i - 1][(i - 2 + 4) % 4] < now) continue;
		if(is[x - 1][(x - 2 + 4) % 4] < now) continue;
		if(min(x, i) <= 2 && max(x, i) > 2 && is[1][3] < now) continue;
		if(x + i != 5 && is[0][2] < now) continue;
		ans.pb(i + '0');
	}
	return ans;
}

void go() {
	int n, m;
	cin >> n >> m;
	cin >> w >> h;
	vector<array<int, 3>> g;
	for(int i = 1, x, y, r; i <= n; i++) {
		cin >> x >> y >> r;
		a[i] = {x, y, r};
		par[i] = i;
		mm[i][3] = x - r;
		mm[i][2] = h - y - r;
		mm[i][1] = w - x - r;
		mm[i][0] = y - r;
	}
	for(int i = 0; i < 4; i++) {
		for(int j = 0; j < 4; j++) {
			is[i][j] = inf;
		}
	}
	for(int i = 1, p, r; i <= m; i++) {
		cin >> p >> r;
		b[i] = {p * (int)1e6, r, i};
	}
	sort(b + 1, b + m + 1);
	for(int i = 1; i <= n; i++) {
		for(int j = i + 1; j <= n; j++) {
			g.pb({dis(a[i][0], a[i][1], a[j][0], a[j][1]) - (a[i][2] + a[j][2]) * (int)1e6, i, j});
		}
	}
	sort(all(g));
	int idx = 0;

	for(int i = 1; i <= m; i++) {
		now = b[i][0] * 2;
		while(idx < g.size() && g[idx][0] < now) {
			untie(g[idx][1], g[idx][2]);
			idx++;
		}
		ans[b[i][2]] = getAns(b[i][1]);
	}

	for(int i = 1; i <= m; i++) {
		cout << ans[i] << '\n';
	}
}

signed main() {
	// #ifndef ONO
	// freopen("file.in", "r", stdin);
	// freopen("file.out", "w", stdout);
	// #endif
	fast;
	int t = 1;
	// cin >> t;
	while(t--) {
		go();
	}
	return 0;
}

Compilation message

park.cpp: In function 'void go()':
park.cpp:112:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |   while(idx < g.size() && g[idx][0] < now) {
      |         ~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 290 ms 52888 KB Output is correct
2 Correct 287 ms 52956 KB Output is correct
3 Correct 284 ms 52896 KB Output is correct
4 Correct 300 ms 52892 KB Output is correct
5 Correct 292 ms 52888 KB Output is correct
6 Correct 298 ms 52980 KB Output is correct
7 Correct 287 ms 52952 KB Output is correct
8 Correct 275 ms 53020 KB Output is correct
9 Correct 2 ms 3412 KB Output is correct
10 Correct 2 ms 3412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 7464 KB Output is correct
2 Correct 42 ms 7688 KB Output is correct
3 Correct 39 ms 7704 KB Output is correct
4 Correct 39 ms 7740 KB Output is correct
5 Correct 43 ms 7780 KB Output is correct
6 Correct 43 ms 7788 KB Output is correct
7 Correct 39 ms 7244 KB Output is correct
8 Correct 41 ms 7328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 290 ms 52888 KB Output is correct
2 Correct 287 ms 52956 KB Output is correct
3 Correct 284 ms 52896 KB Output is correct
4 Correct 300 ms 52892 KB Output is correct
5 Correct 292 ms 52888 KB Output is correct
6 Correct 298 ms 52980 KB Output is correct
7 Correct 287 ms 52952 KB Output is correct
8 Correct 275 ms 53020 KB Output is correct
9 Correct 2 ms 3412 KB Output is correct
10 Correct 2 ms 3412 KB Output is correct
11 Correct 44 ms 7464 KB Output is correct
12 Correct 42 ms 7688 KB Output is correct
13 Correct 39 ms 7704 KB Output is correct
14 Correct 39 ms 7740 KB Output is correct
15 Correct 43 ms 7780 KB Output is correct
16 Correct 43 ms 7788 KB Output is correct
17 Correct 39 ms 7244 KB Output is correct
18 Correct 41 ms 7328 KB Output is correct
19 Correct 321 ms 56372 KB Output is correct
20 Correct 334 ms 56336 KB Output is correct
21 Correct 332 ms 56372 KB Output is correct
22 Correct 326 ms 56248 KB Output is correct
23 Correct 333 ms 56476 KB Output is correct
24 Correct 328 ms 56340 KB Output is correct