QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#281474 | #7846. Glacier Travel | USP_USP_USP# | AC ✓ | 3ms | 3948kb | C++20 | 3.8kb | 2023-12-10 06:30:27 | 2023-12-10 06:30:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define int long long
#define pb push_back
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-9;
bool zero(double x){
return abs(x) <= EPS;
}
using db = long double;
struct point{
double x,y;
point(): x(0), y(0) {}
point(db _x, db _y): x(_x), y(_y) {}
point operator+(point rhs){ return point(x+rhs.x,y+rhs.y); }
point operator-(point rhs){ return point(x-rhs.x,y-rhs.y); }
point operator*(db k){ return point(x*k, y*k); }
point operator/(db k){ return point(x/k, y/k); }
db operator*(point rhs){ return x*rhs.x + y*rhs.y; }
db operator^(point rhs){ return x*rhs.y - y*rhs.x; }
db norm2() { return *this * *this; }
db norm(){ return sqrt(norm2()); }
bool operator==(const point &rhs) const{
return zero(x-rhs.x) && zero(y-rhs.y);
}
};
db dist2(point p, point q){
return (p-q)*(p-q);
}
db dist(point p, point q){
return sqrt(dist2(p,q));
}
double area2(point a, point b, point c){
return (b-a)^(c-a);
}
bool left(point a, point b, point c){
return area2(a,b,c) > EPS;
}
bool right(point a, point b, point c){
return area2(a,b,c) < -EPS;
}
bool collinear(point a, point b, point c){
return zero(area2(a,b,c));
}
int parallel(point a, point b){
a = a/a.norm();
b = b/b.norm();
if(!collinear(point(), a,b)) return 0;
return zero(a.x-b.x) && zero(a.y-b.y) ? 1 : -1;
}
struct segment{
point a,b;
segment(){}
segment(point _a, point _b): a(_a), b(_b) {}
point vec(){ return b-a;}
bool contains(point p){
return a == p || b == p || parallel(a-p,b-p) == -1;
}
point proj(point p){
p = p-a;
point v = vec();
return a + v*((p*v)/(v*v));
}
};
db dist(segment s, point p){
point pr = s.proj(p);
if(s.contains(pr)){
return dist(p,pr);
}
return min(dist(p,s.a),dist(p,s.b));
}
db dist(segment s1, segment s2){
point dir1 = s1.b-s1.a;
point dir2 = s2.b-s2.a;
point dirf = dir2-dir1;
if(zero(dirf.x) && zero(dirf.y)){
return dist(s2.a,s1.a);
}
point s3b = s2.a+dirf;
segment s3(s2.a, s3b);
return dist(s3,s1.a);
}
db norm(point p){
return p.norm();
}
void solve(){
db len;
cin >> len;
int n;
cin >> n;
vector<point> p(n);
for(int i = 0; i < n; i++){
cin >> p[i].x >> p[i].y;
}
vector<db> ini(n);
for(int i = 1; i < n; i++){
ini[i] = ini[i-1] + dist(p[i],p[i-1]);
}
db ans = 1e9;
for(int i = 0; i < n-1; i++){
int l = 0;
int r = n-1;
while(l < r){
int m =(l+r+1)/2;
if(ini[i]+len >= ini[m] || zero(ini[i]+len-ini[m])){
l = m;
}else{
r = m-1;
}
}
if(r == n-1){
if( abs( (ini[i]+len) - ini[r]) <= EPS){
db dis = dist(p[i],p[r]);
ans = min(ans, dis);
}
continue;
}
point dir = p[r+1]-p[r];
db dif = ini[i]+len-ini[r];
dir = dir/norm(dir);
dir = dir*dif;
point a = p[r]+dir;
point b = p[r+1];
point c = p[i];
point dir2 = p[i+1]-p[i];
dir2 = dir2/norm(dir2);
dir2 = dir2*dist(a,b);
point d = p[i]+dir2;
segment s1(a,b);
segment s2(c,d);
db dis = dist(s1,s2);
ans = min(ans, dis);
}
for(int i = 0; i < n-1; i++){
if(ini[i] < len) continue;
int l = 0, r = n-1;
while(l <r){
int m = (l+r+1)/2;
if(ini[i] >= ini[m]+len){
l = m;
}else{
r = m-1;
}
}
point dir = p[r+1]-p[r];
db dif = ini[i]-ini[r]-len;
dir = dir/norm(dir);
dir = dir*dif;
point a = p[r]+dir;
point b = p[r+1];
point c = p[i];
point dir2 = p[i+1]-p[i];
dir2 = dir2/norm(dir2);
dir2 = dir2*dist(a,b);
point d = p[i]+dir2;
segment s1(a,b);
segment s2(c,d);
db dis = dist(s1,s2);
ans = min(ans, dis);
}
cout << fixed << setprecision(10) <<ans << '\n';
}
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: 3644kb
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: 3744kb
input:
3.16227766 9 -2 4 2 4 3 1 4 4 5 1 6 4 10 2 6 1 7 4
output:
0.9999999999
result:
ok found '1.00000', expected '1.00000', error '0.00000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3648kb
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: 0ms
memory: 3748kb
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.0000000000
result:
ok found '0.00000', expected '0.00000', error '-0.00000'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3648kb
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: 2ms
memory: 3772kb
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: 3ms
memory: 3948kb
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: 0ms
memory: 3692kb
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: 3756kb
input:
48.2842712475 4 -10 -10 10 10 -10 10 10 -10
output:
0.0000000000
result:
ok found '0.00000', expected '0.00000', error '-0.00000'