QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#467965#7846. Glacier TravellonelywolfRE 0ms3948kbC++201.8kb2024-07-08 18:28:302024-07-08 18:28:30

Judging History

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

  • [2024-07-08 18:28:30]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3948kb
  • [2024-07-08 18:28:30]
  • 提交

answer

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

using db = double;

constexpr db eps = 1e-9;

int cmp(db a, db b) {
	if (a - b > eps) {
		return 1;
	}
	if (a - b < -eps) {
		return -1;
	}
	return 0;
}

struct Point {
	db x, y;

	Point operator+(const Point& a) {
		return {x + a.x, y + a.y};
	}
	Point operator-(const Point& a) {
		return {x - a.x, y - a.y};
	}
	Point operator*(const db& a) {
		return {x * a, y * a};
	}
	Point operator/(const db& a) {
		return {x / a, y / a};
	}
};

db dis(Point a, Point b) {
	return hypot(a.x - b.x, a.y - b.y);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	cout << fixed << setprecision(10);

	db s;
	int n;
	cin >> s >> n;

	vector<Point> A(n);
	for (auto &[x, y] : A) {
		cin >> x >> y;
	}

	vector<db> sum(n);
	vector<db> tim;
	for (int i = 0; i < n - 1; i++) {
		sum[i + 1] = sum[i] + dis(A[i], A[i + 1]);
	}

	for (int i = 0; i < n; i++) {
		if (cmp(sum[i] + s, sum[n - 1]) <= 0) {
			tim.push_back(sum[i]);
		} 
		if (cmp(sum[i], s) >= 0) {
			tim.push_back(sum[i] - s);
		}
	}
	sort(tim.begin(), tim.end());

	int i1 = 0, i2 = 0;
	auto calc = [&](db t){
		Point p1 = A[i1] + (A[i1 + 1] - A[i1]) / dis(A[i1 + 1], A[i1]) * (t - sum[i1]);
		Point p2 = A[i2] + (A[i2 + 1] - A[i2]) / dis(A[i2 + 1], A[i2]) * (t + s - sum[i2]);
		return dis(p1, p2);
	};

	db ans = 1e100;
	for (int i = 0; i < tim.size() - 1; i++) {
		db t1 = tim[i], t2 = tim[i + 1];
		while (cmp(sum[i1], t1) <= 0) {
			i1++;
		}
		while (cmp(sum[i2], t1 + s) <= 0) {
			i2++;
		}
		i1--, i2--;

		while (t2 - t1 > eps) {
			db lm = (2 * t1 + t2) / 3;
			db rm = (t1 + 2 * t2) / 3;
			if (calc(lm) > calc(rm)) {
				t1 = lm;
			} else {
				t2 = rm;
			}
		}

		ans = min(ans, calc(t1));
	}

	cout << ans << "\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
4
20 0
10 0
10 10
0 10

output:

3.5355339059

result:

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

Test #2:

score: -100
Runtime Error

input:

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

output:


result: