QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#728686 | #8037. Gambler's Ruin | dreamwave | WA | 0ms | 3980kb | C++14 | 1.6kb | 2024-11-09 15:39:49 | 2024-11-09 15:39:51 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define double long double
const double eps = 1e-10;
void solve() {
int n;
std::cin >> n;
std::vector < std::pair < double , int > > a(n);
for(auto &[x, y] : a) std::cin >> x >> y;
std::vector < std::pair < double , int > > used;
std::sort(a.begin(), a.end());
used.emplace_back(0, 0);
for(int i = 0; i < a.size(); ++i) {
if(used.size() == 1) {
used.emplace_back(a[i]);
continue;
}
if(fabs(used.back().first - a[i].first) < eps) {
used.back().second += a[i].second;
} else {
used.emplace_back(a[i]);
}
}
int len = used.size() - 1;
std::vector < int > sum(len + 1);
for(int i = 1; i <= len; ++i) {
sum[i] = sum[i - 1] + used[i].second;
// std::cout << used[i].first << ' ' << used[i].second << '\n';
}
double ans = 0;
for(int r = len, l = 1; r >= 1; --r) {
// if(used[r].first == 0) continue;
double now = (sum[n] - sum[r - 1]) / used[r].first;
while(l < r && sum[l] / (1 - used[l].first) < now) ++l;
ans = std::max(ans, 1.0 * (sum[n] - sum[r - 1]) + 1.0 * sum[l - 1] - now);
if(l >= r) break;
ans = std::max(ans, 1.0 * (sum[n] - sum[r - 1]) + 1.0 * sum[l] - 1.0 * sum[l] / (1.0 - used[l].first));
}
std::cout << std::fixed << std::setprecision(10) << ans << '\n';
}
signed main() {
std::cin.tie(nullptr) -> sync_with_stdio(false);
int T = 1;
while(T--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3940kb
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: 3920kb
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: 3756kb
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: 3824kb
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: 3812kb
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: 3920kb
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: -100
Wrong Answer
time: 0ms
memory: 3980kb
input:
3 0.2 100 0.2 100 0.8 100
output:
0.0000000000
result:
wrong answer 1st numbers differ - expected: '50.0000000', found: '0.0000000', error = '1.0000000'