Submission #63850

# Submission time Handle Problem Language Result Execution time Memory
63850 2018-08-03T05:20:23 Z ainta(#1864) Park (BOI16_park) C++11
100 / 100
446 ms 36388 KB
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int n, m, W, H;
struct point {
	int x, y, r;
}w[2010];
struct Edge {
	int a, b, c;
	bool operator < (const Edge &p)const {
		return c < p.c;
	}
}Ed[3010000];
int cnt, UF[2040], D[5][5];
int Find(int a) {
	if (a == UF[a])return a;
	return UF[a] = Find(UF[a]);
}
void Merge(int a, int b, int c) {
	a = Find(a), b = Find(b);
	if (a == b)return;
	for (int i = 1; i <= 4; i++) {
		if (Find(n + i) == a) {
			for (int j = 1; j <= 4; j++) {
				if (Find(n + j) == b) {
					D[i][j] = D[j][i] = c;
				}
			}
		}
	}
	UF[a] = b;
}
int Res[5][5];
int main() {
	int i, j;
	scanf("%d%d%d%d", &n, &m, &W, &H);
	for (i = 1; i <= n; i++) {
		scanf("%d%d%d", &w[i].x, &w[i].y, &w[i].r);
	}
	for (i = 1; i <= n; i++) {
		for (j = i + 1; j <= n; j++) {
			long long dx = (w[j].x - w[i].x), dy = (w[j].y - w[i].y);
			long long t = sqrt(dx*dx + dy*dy) - w[i].r - w[j].r;
			t = max(0ll, t - 5);
			while ((t + 1 + w[i].r + w[j].r)*(t + 1 + w[i].r + w[j].r) <= dx*dx + dy*dy)t++;
			t /= 2;
			Ed[cnt++] = { i,j,(int)t };
		}
		Ed[cnt++] = { n + 1, i, (w[i].y - w[i].r) / 2 };
		Ed[cnt++] = { n + 2, i, (w[i].x - w[i].r) / 2 };
		Ed[cnt++] = { n + 3, i, (W-w[i].x - w[i].r) / 2 };
		Ed[cnt++] = { n + 4, i, (H-w[i].y - w[i].r) / 2 };
	}
	sort(Ed, Ed + cnt);
	for (i = 1; i <= n + 4; i++) {
		UF[i] = i;
	}
	for (i = 0; i < cnt; i++) {
		Merge(Ed[i].a, Ed[i].b, Ed[i].c);
	}
	Res[1][2] = min(min(D[1][2], D[1][3]), D[1][3]);
	Res[1][3] = min(min(D[1][2], D[1][4]), min(D[3][2], D[3][4]));
	Res[1][4] = min(min(D[2][1], D[2][3]), D[2][4]);
	Res[2][3] = min(min(D[3][1], D[3][2]), D[3][4]);
	Res[2][4] = min(min(D[2][4], D[2][3]), min(D[1][4], D[1][3]));
	Res[3][4] = min(min(D[4][1], D[4][2]), D[4][3]);
	for (i = 1; i <= 4; i++)for (j = 1; j < i; j++)Res[i][j] = Res[j][i];
	while (m--) {
		int a, r, i;
		scanf("%d%d", &r, &a);
		for (i = 1; i <= 4; i++) {
			if (a==i || Res[a][i] >= r)printf("%d", i);
		}
		puts("");
	}
	return 0;
}

Compilation message

park.cpp: In function 'int main()':
park.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d%d", &n, &m, &W, &H);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &w[i].x, &w[i].y, &w[i].r);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:72:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &r, &a);
   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 318 ms 23916 KB Output is correct
2 Correct 338 ms 24036 KB Output is correct
3 Correct 323 ms 24036 KB Output is correct
4 Correct 348 ms 24108 KB Output is correct
5 Correct 301 ms 24108 KB Output is correct
6 Correct 305 ms 24108 KB Output is correct
7 Correct 288 ms 24108 KB Output is correct
8 Correct 296 ms 24228 KB Output is correct
9 Correct 1 ms 24228 KB Output is correct
10 Correct 2 ms 24228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 24228 KB Output is correct
2 Correct 79 ms 24228 KB Output is correct
3 Correct 71 ms 24228 KB Output is correct
4 Correct 72 ms 24228 KB Output is correct
5 Correct 60 ms 24228 KB Output is correct
6 Correct 85 ms 24228 KB Output is correct
7 Correct 58 ms 24228 KB Output is correct
8 Correct 105 ms 24228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 318 ms 23916 KB Output is correct
2 Correct 338 ms 24036 KB Output is correct
3 Correct 323 ms 24036 KB Output is correct
4 Correct 348 ms 24108 KB Output is correct
5 Correct 301 ms 24108 KB Output is correct
6 Correct 305 ms 24108 KB Output is correct
7 Correct 288 ms 24108 KB Output is correct
8 Correct 296 ms 24228 KB Output is correct
9 Correct 1 ms 24228 KB Output is correct
10 Correct 2 ms 24228 KB Output is correct
11 Correct 67 ms 24228 KB Output is correct
12 Correct 79 ms 24228 KB Output is correct
13 Correct 71 ms 24228 KB Output is correct
14 Correct 72 ms 24228 KB Output is correct
15 Correct 60 ms 24228 KB Output is correct
16 Correct 85 ms 24228 KB Output is correct
17 Correct 58 ms 24228 KB Output is correct
18 Correct 105 ms 24228 KB Output is correct
19 Correct 379 ms 31240 KB Output is correct
20 Correct 338 ms 32144 KB Output is correct
21 Correct 366 ms 33300 KB Output is correct
22 Correct 446 ms 34352 KB Output is correct
23 Correct 362 ms 35376 KB Output is correct
24 Correct 323 ms 36388 KB Output is correct