QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#281444 | #7846. Glacier Travel | wnmrmr# | AC ✓ | 20ms | 6124kb | C++23 | 2.6kb | 2023-12-10 05:34:31 | 2023-12-10 05:34:32 |
Judging History
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-8;
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();
for (int i = 0; i < 60; i++) {
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) {
if (p1.i == p2.i) {
double d = t[p1.i] - p2.x;
p1 = walk(p1, d);
p2 = {p2.i + 1, 0};
continue;
}
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: 5940kb
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: 0
Accepted
time: 1ms
memory: 5924kb
input:
3.16227766 9 -2 4 2 4 3 1 4 4 5 1 6 4 10 2 6 1 7 4
output:
1.0000000000
result:
ok found '1.00000', expected '1.00000', error '0.00000'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5920kb
input:
20 5 9 38 36 16 -5 36 -24 15 30 37
output:
2.2935957604
result:
ok found '2.29360', expected '2.29360', error '0.00000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 5944kb
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.0000000001
result:
ok found '0.00000', expected '0.00000', error '0.00000'
Test #5:
score: 0
Accepted
time: 0ms
memory: 5928kb
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.3442144373
result:
ok found '0.34421', expected '0.34421', error '0.00000'
Test #6:
score: 0
Accepted
time: 15ms
memory: 6124kb
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:
0.0445047436
result:
ok found '0.04450', expected '0.04450', error '0.00000'
Test #7:
score: 0
Accepted
time: 20ms
memory: 6068kb
input:
1000 4000 703 909 500 496 -214 628 914 -44 -330 -238 -1424 -1426 347 1420 332 -1417 877 1678 -1390 819 -921 525 121 -923 -851 -859 512 -151 765 -109 416 -1529 -269 667 475 -234 -708 300 1917 -1935 -909 1342 1141 -696 -272 1295 1908 -1124 -898 -1225 1608 630 -1937 1246 -255 1021 -1005 -1650 -1595 -39...
output:
0.0381857100
result:
ok found '0.03819', expected '0.03819', error '0.00000'
Test #8:
score: 0
Accepted
time: 1ms
memory: 5932kb
input:
40 3 100 0 0 100 0 0
output:
15.3073372946
result:
ok found '15.30734', expected '15.30734', error '0.00000'
Test #9:
score: 0
Accepted
time: 0ms
memory: 5928kb
input:
48.2842712475 4 -10 -10 10 10 -10 10 10 -10
output:
0.0000000007
result:
ok found '0.00000', expected '0.00000', error '0.00000'