QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#196576#3854. Radarkaruna#WA 2ms3868kbC++172.8kb2023-10-01 19:41:322023-10-01 19:41:32

Judging History

你现在查看的是最新测评结果

  • [2023-10-01 19:41:32]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3868kb
  • [2023-10-01 19:41:32]
  • 提交

answer

#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 101010;

struct point {
	double x, y;
};
point operator-(point a, point b) { return {a.x - b.x, a.y - b.y}; }
point operator+(point a, point b) { return {a.x + b.x, a.y + b.y}; }
double operator*(point a, point b) { return a.x * b.x + a.y * b.y; }
double operator/(point a, point b) { return a.x * b.y - a.y * b.x; }
point operator*(double k, point a) { return {k * a.x, k * a.y}; }
point unit(point a) {
	double d = sqrtl(a * a);
	return {a.x / d, a.y / d};
}

int n, m, q;
double d[MAXN], e[MAXN];
int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);
	cin >> n >> m >> q;
	for (int i = 0; i < n; i++) {
		cin >> d[i];
	}
	sort(d, d + n);
	for (int i = 0; i < n - 1; i++) {
		e[i] = (d[i] + d[i + 1]) / 2;
	}
	vector<pair<int, pair<int, int>>> points;
	for (int i = 0; i < m; i++) {
		int x, y; cin >> x >> y;
		points.push_back({0, {x, y}});
	}
	for (int i = 1; i <= q; i++) {
		int x, y; cin >> x >> y;
		points.push_back({i, {x, y}});
	}
	auto sgn = [&](pair<int, int> a) {
		return (a.second == 0 && a.first > 0) || a.second > 0;
	};
	sort(points.begin(), points.end(), [&](auto a, auto b) {
		bool b1 = sgn(a.second);
		bool b2 = sgn(b.second);
		if (b1 != b2)
			return b1;
		else {
			auto [x1, y1] = a.second;
			auto [x2, y2] = b.second;
			long long t = x1 * y2 - x2 * y1;
			return t > 0;
		}
	});
	int sz = m + q;
	int best = -1;
	vector<double> ans(q, 1e12);
	for (int i = 0; i < 2 * sz; i++) {
		if (points[i % sz].first == 0) {
			best = i;
			continue;
		}
		else {
			if (best == -1) continue;
			auto [x1, y1] = points[best % sz].second;
			point u = unit({x1, y1});
			auto [x2, y2] = points[i % sz].second;
			point v = {x2, y2};
			int t = points[i % sz].first - 1;
			double ds = u * v;
			int p = lower_bound(e, e + n - 1, ds) - e;
			if (p != 0) {
				ans[t] = min(ans[t], sqrt((v - (d[p - 1] * u)) * (v - (d[p - 1] * u))));
			}
			ans[t] = min(ans[t], sqrt((v - (d[p] * u)) * (v - (d[p] * u))));
		}
	}
	best = -1;
	for (int i = 2 * sz - 1; i >= 0; i--) {
		if (points[i % sz].first == 0) {
			best = i;
			continue;
		}
		else {
			if (best == -1) continue;
			auto [x1, y1] = points[best % sz].second;
			point u = unit({x1, y1});
			auto [x2, y2] = points[i % sz].second;
			point v = {x2, y2};
			int t = points[i % sz].first - 1;

			double ds = u * v;
			int p = lower_bound(e, e + n - 1, ds) - e;
			if (p != 0) {
				ans[t] = min(ans[t], sqrt((v - (d[p - 1] * u)) * (v - (d[p - 1] * u))));
			}
			ans[t] = min(ans[t], sqrt((v - (d[p] * u)) * (v - (d[p] * u))));
		}
	}
	cout.precision(10);
	for (int i = 0; i < q; i++) {
		cout << fixed << ans[i] << '\n';
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3648kb

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.6052910729
0.9777722905
1.5518451054
1.4142135624

result:

ok 4 numbers

Test #2:

score: 0
Accepted
time: 0ms
memory: 3740kb

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.8749850993
15.8749850993
15.8749850993
15.8749850993
15.8749850993
15.8749850993
15.8749850993
15.8749850993
4.9296567010
4.9296567010
4.9296567010
4.9296567010
4.9296567010
4.9296567010
4.9296567010
4.9296567010
2.0000000000
2.0000000000
2.0000000000
2.0000000000
0.0710678119
0.0710678119
0.0710...

result:

ok 32 numbers

Test #3:

score: 0
Accepted
time: 2ms
memory: 3692kb

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.0553851381
4.1231056256
3.6055512755
11.0453610172
15.2970585408
1.4142135624
8.2462112512
7.0000000000
8.9442719100
3.0000000000
12.1655250606
5.0000000000
5.0990195136
11.1803398875
1.4142135624
2.0000000000
2.0000000000
3.0000000000
3.1622776602
8.2462112512
4.4721359550
5.0000000000
8.54400374...

result:

ok 1681 numbers

Test #4:

score: 0
Accepted
time: 0ms
memory: 3868kb

input:

3 4 1681
16
8
4
-1 -1
1 -1
-1 1
1 1
17 1
13 7
-13 -18
-1 18
4 -12
-9 3
5 10
-10 1
-12 -4
14 10
-18 19
0 -3
-7 3
-16 11
-15 9
16 1
-8 -12
3 1
0 -2
15 -18
-14 20
9 -19
17 12
20 5
-3 -6
12 -1
9 10
-13 -9
-20 -15
-11 6
17 -2
-10 -19
15 -8
-6 17
18 15
2 -3
18 -12
8 -3
-11 -6
19 -15
20 0
3 4
2 -16
-6 -17
...

output:

11.7773721193
4.6315936826
6.8956561010
12.2914229054
6.5559640036
4.2703042060
4.3925360004
6.3678258857
6.5559640036
2.9903163794
10.1875203595
2.8336261665
2.9770648314
4.6967798602
4.3522398887
11.3284558098
3.3840301477
1.8364593657
2.9472515164
7.6351318958
9.0921846698
8.0269747761
5.72755681...

result:

ok 1681 numbers

Test #5:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

1 4 16
7
0 1
1 0
0 -1
-1 0
3 0
0 3
-3 0
0 -3
3 3
3 -3
-3 3
-3 -3
8 0
0 8
-8 0
0 -8
8 8
8 -8
-8 8
-8 -8

output:

4.0000000000
4.0000000000
4.0000000000
4.0000000000
5.0000000000
5.0000000000
5.0000000000
5.0000000000
1.0000000000
1.0000000000
1.0000000000
1.0000000000
8.0622577483
8.0622577483
8.0622577483
8.0622577483

result:

ok 16 numbers

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 3824kb

input:

30 4 120
128
1
2
256
4
512
1024
2048
8
4096
32768
131072
262144
524288
8192
268167
16
536334
16384
1047
32
2095
8380
64
134083
65536
4190
67041
33520
16760
536334 0
-536335 0
0 536334
0 -536335
-1 1
-2 2
-4 4
-8 8
-16 16
-32 32
-64 64
-128 128
-256 256
-512 512
-1024 1024
-2048 2048
-4096 4096
-8192...

output:

1.0000000000
2.0000000000
4.0000000000
8.0000000000
16.0000000000
32.0000000000
64.0000000000
128.0000000000
256.0000000000
512.0000000000
1024.0000000000
2048.0000000000
4096.0000000000
8192.0000000000
16384.0000000000
32768.0000000000
65536.0000000000
131072.0000000000
262144.0000000000
524288.000...

result:

wrong answer 21st numbers differ - expected: '1047.0004776', found: '1048.0000000', error = '0.0009547'