QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#607585 | #8037. Gambler's Ruin | longyin | WA | 2ms | 10108kb | C++20 | 1.0kb | 2024-10-03 15:26:41 | 2024-10-03 15:26:41 |
Judging History
answer
#include <bits/stdc++.h>
//#define int long long
#define endl "\n"
using namespace std;
using ll = long long;
const double INF = 1e5;
const int N = 1e6 + 5;
pair<double, ll> a[N];
double p[N];
ll c[N], sc[N];
double getPrice(int l, int r, int n) {
return sc[l] + sc[n] - sc[r - 1] - max(sc[l] * (1 / (1 - p[l])), (sc[n] - sc[r - 1]) * (1 / p[r]));
}
int main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].first >> a[i].second;
}
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++) {
p[i] = a[i].first;
c[i] = a[i].second;
sc[i] = sc[i - 1] + c[i];
}
double ans = -INF;
for (int l = 1, r = n; l <= n; l++) {
double x = getPrice(l, r, n);
while (l < r - 1 && getPrice(l, r - 1, n) >= x) {
r--;
x = getPrice(l, r, n);
}
ans = max(ans, x);
}
cout << fixed << setprecision(20) << ans << endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 10108kb
input:
2 1 15 0 10
output:
10.00000000000000000000
result:
ok found '10.0000000', expected '10.0000000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 9988kb
input:
3 0.4 100 0.5 100 0.6 100
output:
33.33333333333331438553
result:
ok found '33.3333333', expected '33.3333333', error '0.0000000'
Test #3:
score: -100
Wrong Answer
time: 2ms
memory: 10008kb
input:
1 0 1
output:
-100000.00000000000000000000
result:
wrong answer 1st numbers differ - expected: '0.0000000', found: '-100000.0000000', error = '100000.0000000'