QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#729026#8037. Gambler's RuinDFLMKWRWA 1385ms87056kbC++201.6kb2024-11-09 16:22:392024-11-09 16:22:44

Judging History

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

  • [2024-11-09 16:22:44]
  • 评测
  • 测评结果:WA
  • 用时:1385ms
  • 内存:87056kb
  • [2024-11-09 16:22:39]
  • 提交

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 double long double
#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;
	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<int> sy(n + 1);
	int sx = 0;
	for (int i = n - 1; i >= 0; i--) {
		sy[i] = sy[i + 1] + a[i].c;
	}
	
	double res = 0;
	for (int i = 0; i < n; i++) {
		double x = 1.0 / a[i].p;
		sx += a[i].c;
		
		int l = i + 1, r = n, lm, rm;
		double ans = -INF;
		while (l < r) {
			lm = l + (r - l) / 3;
			rm = r - (r - l) / 3;
			
			function<double(int)> check = [&](int mid) -> double {
				if (mid == n) {
					return sx - sx * x;
				}
				return sx + sy[mid] - max(sx * x, sy[mid] * 1.0 / (1.0 - a[mid].p));
			};
			
			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: 3760kb

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

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

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

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

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

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

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

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

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

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: 1385ms
memory: 87056kb

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:

83318447309111.3535919189

result:

wrong answer 1st numbers differ - expected: '85718080941203.0156250', found: '83318447309111.3593750', error = '0.0279945'