QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#281442#7846. Glacier Travelwnmrmr#TL 2ms5960kbC++232.5kb2023-12-10 05:28:062023-12-10 05:28:06

Judging History

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

  • [2023-12-10 05:28:06]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:5960kb
  • [2023-12-10 05:28:06]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define int ll

using ld = long double;
#define double ld

#define all(v) (v).begin(), (v).end()

void dbg_out() { cerr << endl; }
template <typename H, typename... T>
void dbg_out(H h, T... t) { cerr << ' ' << h; dbg_out(t...); }
#define dbg(...) { cerr << #__VA_ARGS__ << ':'; dbg_out(__VA_ARGS__); }

constexpr double EPS = 1e-4;

const int N = 1123456;

double t[N];

struct point {
	double x, y;
	point operator-(point p) const {
		return {x - p.x, y - p.y};
	}
	double size() {
		return sqrt(x * x + y * y);
	}
} pts[N];

struct seg {
	point a, b;
	double size() {
		return (b - a).size();
	}
	point walk(double x) {
		double tt = x / size();
		point diff = b - a;
		return {a.x + tt * diff.x, a.y + tt * diff.y};
	}
};

struct pos {
	int i;
	double x;
	bool operator<(pos o) const {
		return make_pair(i, x) < make_pair(o.i, o.x);
	}
};

pos walk(pos s, double x) {
	if (s.x + x > t[s.i]) return walk({s.i + 1, 0}, x - (t[s.i] - s.x));
	if (s.x + x + EPS > t[s.i]) return {s.i + 1, 0};
	return {s.i, s.x + x};
}

point to_point(pos p) {
	seg s = {pts[p.i], pts[p.i+1]};
	return s.walk(p.x);
}

seg to_seg(pos a, pos b) {
	return {to_point(a), to_point(b)};
}

double dist_pos(pos a, pos b) {
	assert(a.i == b.i);
	return b.x - a.x;
}

double min_dist(seg a, seg b) {
	//b = {b.b, b.a};
	double l = 0, r = a.size();
	while (r - l > EPS) {
		double m1 = l + (r - l) * (1.0 / 3.0);
		double m2 = l + (r - l) * (2.0 / 3.0);
		double dist_m1 = (a.walk(m1) - b.walk(m1)).size();
		double dist_m2 = (a.walk(m2) - b.walk(m2)).size();
		if (dist_m1 > dist_m2) {
			l = m1;
		} else {
			r = m2;
		}
	}
	return (a.walk(r) - b.walk(r)).size();
}

void solve() {
	double s; 
	cin >> s;
	int n; 
	cin >> n;

	for(int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		pts[i] = {x, y};
	}

	for(int i = 0; i < n - 1; i++) {
		seg ss = {pts[i], pts[i + 1]};
		t[i] = ss.size();
	}

	pos p1 = {0, 0};
	pos p2 = walk(p1, s);
	double resp = s;
	while (p2.i != n) {
		dbg(p1.i, p2.i);
		pos pp1 = min(p2, {p1.i, t[p1.i]});
		pos pp2 = {p2.i, t[p2.i]};
		double dist = min(dist_pos(p1, pp1), dist_pos(p2, pp2));
		resp = min(resp, min_dist(to_seg(p1, {p1.i, p1.x + dist}), to_seg(p2, {p2.i, p2.x + dist})));
		p1 = walk(p1, dist);
		p2 = walk(p2, dist);
	}
	
	cout << fixed << setprecision(10);
	cout << resp << endl;
}

signed main() {
	ios::sync_with_stdio(false); cin.tie(0);
	solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5960kb

input:

5
4
20 0
10 0
10 10
0 10

output:

3.5355339065

result:

ok found '3.53553', expected '3.53553', error '0.00000'

Test #2:

score: 0
Accepted
time: 1ms
memory: 5908kb

input:

3.16227766
9
-2 4
2 4
3 1
4 4
5 1
6 4
10 2
6 1
7 4

output:

1.0000000016

result:

ok found '1.00000', expected '1.00000', error '0.00000'

Test #3:

score: 0
Accepted
time: 1ms
memory: 5928kb

input:

20
5
9 38
36 16
-5 36
-24 15
30 37

output:

2.2935957614

result:

ok found '2.29360', expected '2.29360', error '0.00000'

Test #4:

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

input:

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

output:

0.0000746380

result:

ok found '0.00007', expected '0.00000', error '0.00007'

Test #5:

score: 0
Accepted
time: 1ms
memory: 5924kb

input:

10
40
10 11
11 15
6 -16
-18 4
10 10
-10 16
-17 11
2 6
-6 -9
17 -7
-7 -5
10 -18
-9 9
-14 10
19 -3
-14 -3
15 -5
-3 16
-10 14
-9 -12
10 -18
10 -4
-9 -11
11 -2
9 2
12 15
2 -17
-8 -16
19 7
-19 -2
-17 7
16 -9
6 -6
8 -18
15 9
17 2
-19 12
-15 -9
1 -15
19 -12

output:

0.3442144443

result:

ok found '0.34421', expected '0.34421', error '0.00000'

Test #6:

score: -100
Time Limit Exceeded

input:

1000
4000
-720538 -681604
667325 347504
-911397 -962007
-264075 -858319
49605 149209
964851 361021
-397274 28661
-460607 -273701
104862 -136807
-803899 -693703
-974 -337735
323678 -209811
-745617 -358684
-984333 603546
722843 -444579
701511 -255784
-676477 -836480
998942 -227888
-502059 -438394
9641...

output:


result: