QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#728878#8037. Gambler's RuinDFLMKWRWA 1ms3936kbC++201.6kb2024-11-09 16:08:342024-11-09 16:08:35

Judging History

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

  • [2024-11-09 16:08:35]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3936kb
  • [2024-11-09 16:08:34]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define dbg(x) cerr << #x << "=" << x << "\n"
#define MULTI int _; cin >> _; while (_--)

#define int long long
#define ull unsigned long long
typedef long long ll;

const int N = 1e6 + 5, INF = 0x3f3f3f3f3f3f3f3f;

struct Node {
	double p;
	int c;
	
	bool operator<(const Node &x) const {
		return p > x.p;
	}
};

void solve() {
	int n;
	cin >> n;
	
	vector<Node> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i].p >> a[i].c;
	} 
	
	sort(a.begin(), a.end());
	
	vector<double> sy(n + 1);
	double sx = 0;
	for (int i = n - 1; i >= 0; i--) {
		sy[i] = sy[i + 1] + a[i].c;
	}
	
	int fg1 = -1, fg0 = n;
	for (int i = 0; i < n; i++) {
		if (a[i].p == 1) {
			fg1 = max(fg1, i);
		} else if (a[i].p == 0) {
			fg0 = min(fg0, i);
		}
	}
	
	double res = 0;
	for (int i = 0; i < min(n, fg0); i++) {
		double x = 1.0 / a[i].p;
		sx += a[i].c;
		
		int l = max(i + 1, fg1 + 1), r = n - 1, lm, rm;
		double ans = -INF;
		
		function<double(int)> check = [&](int mid) -> double {
			return sx + sy[mid] - max(sx * x, sy[mid] * 1.0 / (1.0 - a[mid].p));
		};
		
		if (l == r) {
			res = max(res, check(l));
		}
		
		while (l < r) {
			lm = l + (r - l) / 3;
			rm = r - (r - l) / 3;
			
			double ck1 = check(lm), ck2 = check(rm);
			if (ck1 < ck2) {
				ans = max(ans, ck2);
				r = rm - 1;
			} else {
				ans = max(ans, ck1);
				l = lm + 1;
			}
		}
		
		res = max(res, ans);
	}
	
	cout << fixed << setprecision(10);
	cout << res << "\n";
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	solve();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3816kb

input:

2
1 15
0 10

output:

10.0000000000

result:

ok found '10.0000000', expected '10.0000000', error '0.0000000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3912kb

input:

3
0.4 100
0.5 100
0.6 100

output:

33.3333333333

result:

ok found '33.3333333', expected '33.3333333', error '0.0000000'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3936kb

input:

1
0 1

output:

0.0000000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3872kb

input:

2
1 0
1 100

output:

0.0000000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3868kb

input:

1
0.5 100

output:

0.0000000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 3936kb

input:

3
0.4 100
0.6 100
0.6 100

output:

33.3333333333

result:

wrong answer 1st numbers differ - expected: '0.0000000', found: '33.3333333', error = '33.3333333'