QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#206393 | #5505. Great Chase | dkdk | WA | 1ms | 3704kb | C++20 | 1.8kb | 2023-10-07 20:17:31 | 2023-10-07 20:17:32 |
Judging History
answer
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <cmath>
#include <string>
#include <set>
#include <iomanip>
#define ft first
#define sd second
#define endl '\n'
#define lowbit(x) (x & (-x))
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PDI = pair<double, int>;
using i128 = __int128;
const double eps = 1e-8;
const int N = 1010, mod = 998244353, INF = 2147483647;
int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
int n;
double v;
vector<PDI> a, b;
bool check(double t)
{
double xa = -1e18, xb = 1e18;
for(auto o : a)
{
double p = o.ft, v = o.sd;
xa = max(xa, p + v * t);
}
for(auto o : b)
{
double p = o.ft, v = o.sd;
xb = min(xb, p - v * t);
}
if(xa > xb)return true;
else return false;
}
void solve()
{
cin >> n >> v;
a.clear(), b.clear();
for(int i = 0; i < n ; i++)
{
double x, y;
cin >> x >> y;
if(x < 0)a.push_back({x, y});
else b.push_back({x, y});
}
double l = 0, r = (b.back().ft - a.back().ft) / (b.back().sd + a.back().sd);
while(r - l > eps)
{
double mid = (l + r) / 2;
//cout << r - l << endl;
if(check(mid))r = mid;
else l = mid;
}
//cout << l << ' ' << r << ' ' << eps << endl;
cout << l * v << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
cout << setprecision(20);
while(t -- )solve();
return 0;
}
/*
3
4 9
10 2
-7 2
-6 1
7 1
2 8
-1 7
1 6
2 3
-1000000000000 1
1000000000000 1
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3704kb
input:
3 4 9 10 2 -7 2 -6 1 7 1 2 8 -1 7 1 6 2 3 -1000000000000 1 1000000000000 1
output:
38.249999953899532557 1.2307691574096679688 3000000000000
result:
wrong answer 2nd numbers differ - expected: '1.2307692', found: '1.2307692', error = '0.0000001'