QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#87357#5505. Great Chasechiranko#WA 893ms3712kbC++141.1kb2023-03-12 18:18:402023-03-12 18:18:46

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-12 18:18:46]
  • 评测
  • 测评结果:WA
  • 用时:893ms
  • 内存:3712kb
  • [2023-03-12 18:18:40]
  • 提交

answer

#include <bits/stdc++.h>
#define pb emplace_back

#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)

using namespace std;

using LDB = long double;
using DB = double;
using LL = long long;

void solve()
{
	LDB eps = 1e-12;
	int n;
	LDB v;
	scanf("%d%Lf", &n, &v);
	vector<LDB> pos(n + 1, 0), speed(n + 1, 0);
	for(int i = 1; i <= n; ++i){
		scanf("%Lf%Lf", &pos[i], &speed[i]);
	}

	LDB l = 0.0, r = 1e12, mid = 0, round = 0;
	while(r - l > eps){
		++round;
		mid = (l + r) / 2;
		if(r - l > eps){
			if(r - mid <= eps){
				l = mid;
				break;
			}
			else if(mid - l <= eps){
				r = mid;
				break;
			}
		}
		
		
		LDB maxl = -1e12 - 1, minr = 1e12 + 1;
		for(int i = 1; i <= n; ++i){
			if(pos[i] < 0)
				maxl = max(maxl, pos[i] + mid * speed[i]);
			else
				minr = min(minr, pos[i] - mid * speed[i]);
		}
		
		if(maxl >= minr)
			r = mid;
		else
			l = mid;
		// printf("%.12Lf %.12Lf %.12Lf\n", l, r, r - l);
		

		
	}
	printf("%.12Lf\n", l * v);
}

int main()
{
	// ios::sync_with_stdio(0);
	// cin.tie(0);

	int T;
	scanf("%d", &T);
	while(T--){
		solve();
	}
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3712kb

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.250000000006
1.230769230769
3000000000000.000000000000

result:

ok 3 numbers

Test #2:

score: -100
Wrong Answer
time: 893ms
memory: 3696kb

input:

10000
200 997007
405524182320 754760
686939601648 419804
687047488212 715566
1446157132 4594
-670522037 4673
763634629282 253755
424307411732 275041
1582708381 8473
-667425982 4622
-522841486 1427
702430907988 460271
1405423646 1060
1497754648 6227
883363410675 723547
56899800372 46435
-810216390 64...

output:

145405766328.349110141397
16414958969.727280461229
5202715639.835184003226
321977234.156326140132
45384199210.221684243530
183885744.769230752412
1708925225.230472844793
89786664971.557942003012
13924365606.287388203666
412975327.555555664760
965508404.512101928063
4703493416.288376164623
352961619....

result:

wrong answer 4566th numbers differ - expected: '1.0000010', found: '1.0000010', error = '0.0000000'