# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
529434 |
2022-02-23T02:19:40 Z |
KoD |
Park (BOI16_park) |
C++17 |
|
2391 ms |
1764 KB |
#include <bits/stdc++.h>
using std::vector;
using std::array;
using std::tuple;
using std::pair;
struct UnionFind {
vector<int> par;
UnionFind(const int n) : par(n, -1) {}
void reset() {
std::fill(par.begin(), par.end(), -1);
}
int find(const int u) {
return par[u] < 0 ? u : par[u] = find(par[u]);
}
void merge(int x, int y) {
x = find(x), y = find(y);
if (x == y) return;
if (par[x] > par[y]) std::swap(x, y);
par[x] += par[y];
par[y] = x;
}
};
using ll = long long;
constexpr ll sq(const ll x) {
return x * x;
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int N, M;
std::cin >> N >> M;
int W, H;
std::cin >> W >> H;
vector<int> X(N), Y(N), R(N);
for (int i = 0; i < N; ++i) {
std::cin >> X[i] >> Y[i] >> R[i];
}
UnionFind dsu(N + 4);
const auto set_radius = [&](const int rad) {
dsu.reset();
for (int i = 0; i < N; ++i) {
if (Y[i] < R[i] + 2 * rad) {
dsu.merge(i, N);
}
if (H - Y[i] < R[i] + 2 * rad) {
dsu.merge(i, N + 1);
}
if (X[i] < R[i] + 2 * rad) {
dsu.merge(i, N + 2);
}
if (W - X[i] < R[i] + 2 * rad) {
dsu.merge(i, N + 3);
}
}
for (int i = 0; i < N; ++i) {
for (int j = 0; j < i; ++j) {
if (sq(X[i] - X[j]) + sq(Y[i] - Y[j]) < sq(R[i] + R[j] + 2 * rad)) {
dsu.merge(i, j);
}
}
}
};
array<array<int, 4>, 4> thres = {};
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < i; ++j) {
int ok = 0, ng = 1000000000;
while (ng - ok > 1) {
const int md = (ok + ng) / 2;
set_radius(md);
(dsu.find(N + i) != dsu.find(N + j) ? ok : ng) = md;
}
thres[i][j] = thres[j][i] = ok;
}
}
array<array<int, 4>, 4> reach = {};
reach[0][1] = std::min({thres[0][1], thres[0][2], thres[0][3]});
reach[0][3] = std::min({thres[2][0], thres[2][1], thres[2][3]});
reach[1][2] = std::min({thres[3][0], thres[3][1], thres[3][2]});
reach[2][3] = std::min({thres[1][0], thres[1][2], thres[1][3]});
reach[0][2] = std::min({thres[0][1], thres[0][2], thres[3][1], thres[3][2]});
reach[1][3] = std::min({thres[0][1], thres[0][3], thres[2][1], thres[2][3]});
while (M--) {
int rad, i;
std::cin >> rad >> i;
i -= 1;
for (int j = 0; j < 4; ++j) {
if (i == j or rad <= reach[std::min(i, j)][std::max(i, j)]) {
std::cout << j + 1;
}
}
std::cout << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
851 ms |
332 KB |
Output is correct |
2 |
Correct |
875 ms |
452 KB |
Output is correct |
3 |
Correct |
869 ms |
332 KB |
Output is correct |
4 |
Correct |
923 ms |
332 KB |
Output is correct |
5 |
Correct |
918 ms |
332 KB |
Output is correct |
6 |
Correct |
884 ms |
336 KB |
Output is correct |
7 |
Correct |
2383 ms |
332 KB |
Output is correct |
8 |
Correct |
2391 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
580 KB |
Output is correct |
2 |
Correct |
39 ms |
636 KB |
Output is correct |
3 |
Correct |
40 ms |
564 KB |
Output is correct |
4 |
Correct |
39 ms |
580 KB |
Output is correct |
5 |
Correct |
37 ms |
592 KB |
Output is correct |
6 |
Correct |
50 ms |
580 KB |
Output is correct |
7 |
Correct |
27 ms |
1668 KB |
Output is correct |
8 |
Correct |
27 ms |
1736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
851 ms |
332 KB |
Output is correct |
2 |
Correct |
875 ms |
452 KB |
Output is correct |
3 |
Correct |
869 ms |
332 KB |
Output is correct |
4 |
Correct |
923 ms |
332 KB |
Output is correct |
5 |
Correct |
918 ms |
332 KB |
Output is correct |
6 |
Correct |
884 ms |
336 KB |
Output is correct |
7 |
Correct |
2383 ms |
332 KB |
Output is correct |
8 |
Correct |
2391 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
42 ms |
580 KB |
Output is correct |
12 |
Correct |
39 ms |
636 KB |
Output is correct |
13 |
Correct |
40 ms |
564 KB |
Output is correct |
14 |
Correct |
39 ms |
580 KB |
Output is correct |
15 |
Correct |
37 ms |
592 KB |
Output is correct |
16 |
Correct |
50 ms |
580 KB |
Output is correct |
17 |
Correct |
27 ms |
1668 KB |
Output is correct |
18 |
Correct |
27 ms |
1736 KB |
Output is correct |
19 |
Correct |
963 ms |
1720 KB |
Output is correct |
20 |
Correct |
917 ms |
1644 KB |
Output is correct |
21 |
Correct |
908 ms |
1720 KB |
Output is correct |
22 |
Correct |
923 ms |
1588 KB |
Output is correct |
23 |
Correct |
899 ms |
1596 KB |
Output is correct |
24 |
Correct |
2283 ms |
1764 KB |
Output is correct |