QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#253288 | #3854. Radar | oogerbooger# | WA | 2ms | 3760kb | C++14 | 4.3kb | 2023-11-16 20:52:46 | 2023-11-16 20:52:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ld = long double;
using ll = long long;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
const int INF = 1e7;
struct Point {
int x, y, id; // jak id < 0 tzn, że jestem pałągiem
};
ll scalar(Point a, Point b) {
return a.x * 1LL * b.x + a.y * 1LL * b.y;
}
double len(Point a) {
return sqrt(scalar(a, a));
}
ll det(Point a, Point b) {
return a.x * 1LL * b.y - a.y * 1LL * b.x;
}
ld dl_rzutu_a_na_b(Point a, Point b) {
return (ld)scalar(a, b) / len(b);
}
int32_t main() {
ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);
int R, F, N; cin >> R >> F >> N;
vector<int> radii(R + 2, 0);
for (int i = 1; i <= R; i++) {
cin >> radii[i];
}
radii[R + 1] = INF;
sort(begin(radii), end(radii));
vector<Point> all_pts(F + N), pts(N), paly(F);
for (int i = 0; i < F; i++) {
int fx, fy; cin >> fx >> fy;
all_pts[i] = {fx, fy, -(i + 1)};
paly[i] = all_pts[i];
}
for (int i = 0; i < N; i++) {
int x, y; cin >> x >> y;
all_pts[i + F] = {x, y, (i + 1)};
pts[i] = all_pts[i + F];
}
auto pom = [&](Point p) {
if (p.x >= 0 && p.y == 0) return 0; // na prawej półprostej
if (p.y > 0) return 1; // na górnym półokregu
if (p.x < 0 && p.y == 0) return 2; // na lewej półprostej
return 3; // na dole
};
int pom_a, pom_b; // zmienne pomocnicze
auto cmp = [&](Point a, Point b) {
pom_a = pom(a), pom_b = pom(b);
if (pom_a != pom_b) return pom_a < pom_b;
if (det(a, b) == 0) return a.id < b.id; // lz więc porównuję id
return det(a, b) >= 0;
};
sort(all_pts.begin(), all_pts.end(), cmp);
vector<int> Left(N), Right(N);
int M = N + F;
int it = 0;
while (all_pts[it].id > 0) it = (it - 1 + M) % M;
int pre_left = all_pts[it].id;
for (int i = 0; i < F + N; i++) {
if (all_pts[i].id < 0) pre_left = all_pts[i].id;
else {
Left[all_pts[i].id - 1] = pre_left;
}
}
it = M - 1;
while (all_pts[it].id > 0) it = (it + 1) % M;
int pre_right = all_pts[it].id;
for (int i = F + N - 1; i >= 0; i--) {
if (all_pts[i].id < 0) pre_right = all_pts[i].id;
else {
Right[all_pts[i].id - 1] = pre_right;
}
}
cout << fixed << setprecision(15);
auto cur_mini = [&](int i, int idx) {
ld mini = INF;
ld rzut = dl_rzutu_a_na_b(pts[i], paly[idx]);
it = int(upper_bound(begin(radii), end(radii), rzut) - begin(radii));
if(it > 0 && it < R+1) {
int r = radii[it];
ld norma = sqrt((ld)paly[idx].x*paly[idx].x+(ld)paly[idx].y*paly[idx].y);
ld ax = (ld)paly[idx].x*r/norma;
ld ay = (ld)paly[idx].y*r/norma;
mini = min(mini, sqrt((ax-pts[i].x)*(ax-pts[i].x)+(ay-pts[i].y)*(ay-pts[i].y) ));
}
it--;
if(it > 0 && it < R+1) {
int r = radii[it];
ld norma = sqrt((ld)paly[idx].x*paly[idx].x+(ld)paly[idx].y*paly[idx].y);
ld ax = (ld)paly[idx].x*r/norma;
ld ay = (ld)paly[idx].y*r/norma;
mini = min(mini, sqrt((ax-pts[i].x)*(ax-pts[i].x)+(ay-pts[i].y)*(ay-pts[i].y) ));
}
return mini;
};
for (int i = 0; i < N; i++) {
if(pts[i].x == 0 && pts[i].y == 0) {
cout << radii[1] << "\n";
}
ld mini = cur_mini(i, -Left[i]-1);
ld mini2 = cur_mini(i, -Right[i]-1);
cout << min(mini, mini2) << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3760kb
input:
3 8 4 2 4 7 1 0 2 1 0 1 -1 1 -5 -2 -5 -6 -2 -7 6 -1 -1 -1 3 1 -5 -3 8 1
output:
0.605291072916640 0.977772290465605 1.551845105401790 1.414213562373095
result:
ok 4 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
1 8 32 7 0 1 1 0 0 -1 -1 0 1 -1 -1 1 -1 -1 1 1 20 10 10 20 -20 10 10 -20 -10 20 20 -10 -10 -20 -20 -10 2 1 1 2 -2 1 1 -2 -1 2 2 -1 -1 -2 -2 -1 5 0 0 5 -5 0 0 -5 5 5 5 -5 -5 5 -5 -5 9 0 0 9 -9 0 0 -9 9 9 9 -9 -9 9 -9 -9
output:
15.874985099257575 15.874985099257575 15.874985099257575 15.874985099257575 15.874985099257575 15.874985099257575 15.874985099257575 15.874985099257575 4.929656701045723 4.929656701045723 4.929656701045723 4.929656701045723 4.929656701045723 4.929656701045723 4.929656701045723 4.929656701045723 2.00...
result:
ok 32 numbers
Test #3:
score: -100
Wrong Answer
time: 2ms
memory: 3700kb
input:
3 4 1681 16 8 4 -1 0 0 -1 0 1 1 0 -9 17 -4 -7 2 -13 -11 -17 15 -19 -7 1 -8 14 -8 -7 -8 20 -16 -3 12 14 -3 12 9 -5 -18 11 3 -1 2 0 -18 0 0 -19 -1 -19 18 -8 2 20 5 -8 -8 -19 -9 -16 20 -19 14 -1 3 10 -1 -4 4 10 16 17 19 -7 -17 4 1 -12 -5 -12 -5 -10 -15 -5 -10 -19 -2 -10 -4 -16 -2 4 -14 8 -17 16 4 1 16 ...
output:
9.055385138137417 4.123105625617661 3.605551275463989 11.045361017187261 15.297058540778354 1.414213562373095 8.246211251235321 7.000000000000000 8.944271909999159 3.000000000000000 12.165525060596439 5.000000000000000 5.099019513592785 11.180339887498948 1.414213562373095 2.000000000000000 2.000000...
result:
wrong answer 994th numbers differ - expected: '4.4721360', found: '4.0000000', error = '0.1055728'