#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
const int N = 2000;
const int INF = 0x7fffffff;
int xx[N + 1], yy[N + 1], rr[N + 1];
int ww[N + 2][N + 2], dd[N + 2];
int dijkstra(int n) {
for (int i = 0; i < n; i++)
dd[i] = INF;
dd[0] = 0;
for (int h = 0; h < n; h++) {
int i = -1;
for (int j = 0; j < n; j++)
if (dd[j] != -1 && (i == -1 || dd[i] > dd[j]))
i = j;
int d = dd[i]; dd[i] = -1;
if (i == n - 1)
return d;
for (int j = 0; j < n; j++)
dd[j] = min(dd[j], max(d, ww[i][j]));
}
return -1;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL);
int n, q; cin >> n >> q;
int x_, y_; cin >> x_ >> y_;
for (int i = 1; i <= n; i++)
cin >> xx[i] >> yy[i] >> rr[i];
ww[0][n + 1] = min(x_, y_);
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
ww[i][j] = ww[j][i] = (int) hypot(xx[j] - xx[i], yy[j] - yy[i]) - rr[i] - rr[j];
for (int i = 1; i <= n; i++) {
ww[0][i] = ww[i][0] = yy[i] - rr[i];
ww[i][n + 1] = ww[n + 1][i] = min(min(xx[i], x_ - xx[i]), y_ - yy[i]) - rr[i];
}
int d12 = dijkstra(n + 2);
for (int i = 1; i <= n; i++) {
ww[0][i] = ww[i][0] = min(yy[i], x_ - xx[i]) - rr[i];
ww[i][n + 1] = ww[n + 1][i] = min(xx[i], y_ - yy[i]) - rr[i];
}
int d13 = dijkstra(n + 2);
for (int i = 1; i <= n; i++) {
ww[0][i] = ww[i][0] = xx[i] - rr[i];
ww[i][n + 1] = ww[n + 1][i] = min(min(yy[i], y_ - yy[i]), x_ - xx[i]) - rr[i];
}
int d14 = dijkstra(n + 2);
for (int i = 1; i <= n; i++) {
ww[0][i] = ww[i][0] = x_ - xx[i] - rr[i];
ww[i][n + 1] = ww[n + 1][i] = min(min(yy[i], y_ - yy[i]), xx[i]) - rr[i];
}
int d23 = dijkstra(n + 2);
for (int i = 1; i <= n; i++) {
ww[0][i] = ww[i][0] = min(xx[i], yy[i]) - rr[i];
ww[i][n + 1] = ww[n + 1][i] = min(x_ - xx[i], y_ - yy[i]) - rr[i];
}
int d24 = dijkstra(n + 2);
for (int i = 1; i <= n; i++) {
ww[0][i] = ww[i][0] = y_ - yy[i] - rr[i];
ww[i][n + 1] = ww[n + 1][i] = min(min(xx[i], x_ - xx[i]), yy[i]) - rr[i];
}
int d34 = dijkstra(n + 2);
while (q--) {
int d, a; cin >> d >> a, d *= 2;
if (a == 1) {
cout << 1;
if (d12 >= d)
cout << 2;
if (d13 >= d)
cout << 3;
if (d14 >= d)
cout << 4;
} else if (a == 2) {
if (d12 >= d)
cout << 1;
cout << 2;
if (d23 >= d)
cout << 3;
if (d24 >= d)
cout << 4;
} else if (a == 3) {
if (d13 >= d)
cout << 1;
if (d23 >= d)
cout << 2;
cout << 3;
if (d34 >= d)
cout << 4;
} else {
if (d14 >= d)
cout << 1;
if (d24 >= d)
cout << 2;
if (d34 >= d)
cout << 3;
cout << 4;
}
cout << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |