QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#729047#8037. Gambler's RuinDFLMKWRWA 997ms59372kbC++201.8kb2024-11-09 16:25:122024-11-09 16:25:19

Judging History

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

  • [2024-11-09 16:25:19]
  • 评测
  • 测评结果:WA
  • 用时:997ms
  • 内存:59372kb
  • [2024-11-09 16:25:12]
  • 提交

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;

/*
3
0.2 100
0.2 100
0.8 100
*/

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;
	map<double, int> mp;
	
	for (int i = 0; i < n; i++) {
		double p;
		int c;
		cin >> p >> c;
		mp[p] += c;
	}
	for (auto it : mp) {
		a.push_back({it.first, it.second});
	}
	
	n = a.size();
	
	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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3940kb

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: 3944kb

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: 3944kb

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: 3936kb

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: 3872kb

input:

1
0.5 100

output:

0.0000000000

result:

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

Test #6:

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

input:

3
0.4 100
0.6 100
0.6 100

output:

0.0000000000

result:

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

Test #7:

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

input:

3
0.2 100
0.2 100
0.8 100

output:

50.0000000000

result:

ok found '50.0000000', expected '50.0000000', error '0.0000000'

Test #8:

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

input:

2
0.999999 1000000
0.999998 2

output:

0.9999990000

result:

ok found '0.9999990', expected '0.9999990', error '0.0000000'

Test #9:

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

input:

2
0 100000
0.000001 1

output:

0.0000000000

result:

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

Test #10:

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

input:

2
0 1000000000
0.000001 1

output:

1.0000000000

result:

ok found '1.0000000', expected '1.0000000', error '0.0000000'

Test #11:

score: -100
Wrong Answer
time: 997ms
memory: 59372kb

input:

1000000
0.375733 595197307
0.505261 377150668
0.517039 15795246
0.448099 228176467
0.529380 871983979
0.905546 876268308
0.095891 272104456
0.500302 916153337
0.128705 355768079
0.070600 78747362
0.444107 466118868
0.194987 298494965
0.462293 593292779
0.287909 838058266
0.237226 934603199
0.391909 ...

output:

83319027551179.3750000000

result:

wrong answer 1st numbers differ - expected: '85718080941203.0156250', found: '83319027551179.3750000', error = '0.0279877'