QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#788910 | #8037. Gambler's Ruin | lmx111 | WA | 0ms | 3920kb | C++20 | 1.7kb | 2024-11-27 18:43:32 | 2024-11-27 18:43:33 |
Judging History
answer
// Coded by hjxddl
#include <bits/stdc++.h>
#define ll long long
#define db double
const int N = 2e5 + 5;
const db eps = 1e-6;
int n;
std::vector<ll> pre;
std::vector<std::pair<db, int>> a;
db cul(int l, int r) {
ll sx = pre[l], sy = pre[n] - pre[r - 1];
if (a[l].first == 0)
return sx;
if (a[r].first == 1)
return sy;
return sx + sy - std::max(sx / a[l].first, sy / (1 - a[r].first));
}
void solve() {
std::cin >> n;
a.resize(n + 5), pre.resize(n + 5);
for (int i = 1; i <= n; i++) {
std::cin >> a[i].first >> a[i].second;
a[i].first *= -1;
}
std::sort(a.begin() + 1, a.begin() + n + 1);
for (int i = 1; i <= n; i++) {
a[i].first *= -1;
pre[i] = pre[i - 1] + a[i].second;
}
pre[n + 1] = pre[n];
db ans = 0;
for (int i = 1; i < n; i++) {
while (i < n && a[i].first == a[i + 1].first) i++;
if (i >= n) break;
int l = i + 1, r = n, lmid = l + (r - l + 1) / 3, rmid = r - (r - l + 1) / 3;
while (l < r) {
db s1 = cul(i, lmid), s2 = cul(i, rmid);
if (fabs(s1 - s2) <= eps) {
l = lmid + 1;
r = rmid - 1;
}
else if (s1 > s2) {
r = rmid - 1;
}
else if (s1 < s2) {
l = lmid + 1;
}
lmid = l + (r - l + 1) / 3, rmid = r - (r - l + 1) / 3;
}
ans = std::max(ans, cul(i, l));
}
std::cout << std::fixed << std::setprecision(12) << ans << '\n';
}
int main() {
std::ios::sync_with_stdio(0);
std::cin.tie(0), std::cout.tie(0);
int t = 1;
// std::cin >> t;
while (t--) {
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3820kb
input:
2 1 15 0 10
output:
10.000000000000
result:
ok found '10.0000000', expected '10.0000000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
3 0.4 100 0.5 100 0.6 100
output:
33.333333333333
result:
ok found '33.3333333', expected '33.3333333', error '0.0000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
1 0 1
output:
0.000000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3920kb
input:
2 1 0 1 100
output:
0.000000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
1 0.5 100
output:
0.000000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
3 0.4 100 0.6 100 0.6 100
output:
0.000000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #7:
score: -100
Wrong Answer
time: 0ms
memory: 3676kb
input:
3 0.2 100 0.2 100 0.8 100
output:
75.000000000000
result:
wrong answer 1st numbers differ - expected: '50.0000000', found: '75.0000000', error = '0.5000000'