QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#789245 | #8037. Gambler's Ruin | lmx111 | WA | 736ms | 77060kb | C++20 | 1.8kb | 2024-11-27 19:39:30 | 2024-11-27 19:39:34 |
Judging History
answer
// Coded by hjxddl
#include <bits/stdc++.h>
#define ll long long
#define db long double
const int N = 2e5 + 5;
const db eps = 1e-6;
int n;
std::vector<ll> pre;
std::vector<std::pair<db, ll>> a, b;
db cul(int l, int r) {
ll sx = pre[l], sy = pre[n] - pre[r - 1];
if (a[l].first == 0 || a[r].first == 1)
return 0;
return sx + sy - std::max(sx / b[l].first, sy / (1 - b[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);
b.push_back({0, 0});
for (int i = 1; i <= n; i++) {
ll sum = a[i].second;
while (i < n && a[i].first == a[i + 1].first)
i++, sum += a[i].second;
b.push_back({-a[i].first, sum});
}
n = b.size() - 1;
for (int i = 1; i <= n; i++)
pre[i] = pre[i - 1] + b[i].second;
db ans = 0;
for (int i = 1; i < n; i++) {
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;
while (t--) {
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3800kb
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: 3888kb
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: 3868kb
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: 3828kb
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: 3940kb
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: 3824kb
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: 0
Accepted
time: 0ms
memory: 3832kb
input:
3 0.2 100 0.2 100 0.8 100
output:
50.000000000000
result:
ok found '50.0000000', expected '50.0000000', error '0.0000000'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3880kb
input:
2 0.999999 1000000 0.999998 2
output:
0.999998999999
result:
ok found '0.9999990', expected '0.9999990', error '0.0000000'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
2 0 100000 0.000001 1
output:
0.000000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
2 0 1000000000 0.000001 1
output:
1.000000000000
result:
ok found '1.0000000', expected '1.0000000', error '0.0000000'
Test #11:
score: -100
Wrong Answer
time: 736ms
memory: 77060kb
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:
85717913550404.864364624023
result:
wrong answer 1st numbers differ - expected: '85718080941203.0156250', found: '85717913550404.8593750', error = '0.0000020'