QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#750450 | #8037. Gambler's Ruin | ucup-team5217# | WA | 1ms | 6016kb | C++23 | 1.1kb | 2024-11-15 14:36:21 | 2024-11-15 14:36:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define maxn 1000005
typedef pair<double, int64_t> pdl;
pdl a[maxn];
double pre[maxn];
void solve(void) {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
sort(a + 1, a + n + 1);
double ans = 0;
for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + a[i].second;
for (int i = 0, j = 0; i <= n; i++) {
if (i < n && a[i + 1].first == 0) continue;
double Sx = pre[n] - pre[i], x = (i < n ? 1 / a[i + 1].first : 0);
while (j < i && a[j + 1].first < 1 && pre[j + 1] * (1 / (1 - a[j + 1].first)) <= Sx * x) j++;
if (j > 0 && a[j].first < 1) ans = max(ans, Sx + pre[j] - max(Sx * x, pre[j] * (1 / (1 - a[j].first))));
if (j < i && a[j + 1].first < 1)
ans = max(ans, Sx + pre[j + 1] - max(Sx * x, pre[j + 1] * (1 / (1 - a[j + 1].first))));
}
cout << setprecision(10) << fixed << ans << endl;
return;
}
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int _ = 1;
while (_--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5956kb
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: 1ms
memory: 5956kb
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: 1ms
memory: 5996kb
input:
1 0 1
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 6016kb
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: 1ms
memory: 5888kb
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: 1ms
memory: 5956kb
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'