QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#268587 | #7846. Glacier Travel | PetroTarnavskyi# | AC ✓ | 13ms | 5804kb | C++20 | 2.1kb | 2023-11-28 18:45:50 | 2023-11-28 18:45:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); i--)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
struct pt
{
db x, y;
pt() {}
pt(db _x, db _y) : x(_x), y(_y) {}
pt operator+(const pt p) const
{
return pt(x + p.x, y + p.y);
}
pt operator-(const pt p) const
{
return pt(x - p.x, y - p.y);
}
pt operator*(db coef) const
{
return pt(x * coef, y * coef);
}
db len()
{
return sqrt(x * x + y * y);
}
pt scale(db val)
{
return *this * (val / len());
}
};
const int N = 1 << 20;
pt p[N];
db t[N]; //p[i] -> p[i + 1] start in t[i]
db s;
db val(int i0, int i1, db m)
{
pt p0 = p[i0] + (p[i0 + 1] - p[i0]).scale(m - t[i0]);
pt p1 = p[i1] + (p[i1 + 1] - p[i1]).scale(s + m - t[i1]);
return (p0 - p1).len();
}
db find(int i0, int i1, db tL, db tR)
{
FOR(it, 0, 70)
{
db m1 = (tL * 2 + tR) / 3;
db m2 = (tR * 2 + tL) / 3;
if(val(i0, i1, m1) > val(i0, i1, m2))
tL = m1;
else
tR = m2;
}
return val(i0, i1, tL);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> s >> n;
FOR(i, 0, n)
cin >> p[i].x >> p[i].y;
FOR(i, 0, n - 1)
{
t[i + 1] = t[i] + (p[i + 1] - p[i]).len();
}
vector<pair<db, int>> events;
FOR(i, 1, n)
{
//t + s;
events.PB(MP(t[i] - s, 1));
events.PB(MP(t[i], 0));
}
sort(ALL(events));
db ans = s;
int i0 = 0, i1 = 0;
db prevT = 0;
for(auto [time, ind] : events)
{
if(time > 0)
{
ans = min(ans, find(i0, i1, prevT, time));
//cout << i0 << " " << i1 << " " << prevT << " " << time << endl;
prevT = time;
}
if(ind == 1)
i1++;
else
i0++;
if(i1 == n - 1 || i0 == n - 1)
break;
}
cout << fixed << setprecision(10) << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5672kb
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: 5688kb
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: 1ms
memory: 5804kb
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: 5632kb
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: 1ms
memory: 5616kb
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: 13ms
memory: 5800kb
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: 13ms
memory: 5776kb
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: 5636kb
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: 5720kb
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'