QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#664772 | #8037. Gambler's Ruin | crychic | WA | 1ms | 6000kb | C++17 | 1.4kb | 2024-10-21 22:15:24 | 2024-10-21 22:15:24 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long; using pii = pair<int, int>;
template <typename A, typename B> bool smax(A &a, const B &b) { return a < b ? a = b, 1 : 0; }
template <typename A, typename B> bool smin(A &a, const B &b) { return b < a ? a = b, 1 : 0; }
constexpr int N = 1e6 + 7;
constexpr double eps = 1e-10;
int n;
pair<double, ll> a[N];
ll pres[N], sufs[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i].first >> a[i].second;
sort(a + 1, a + n + 1, greater<pair<double, int>>());
int cnt = 0;
for (int i = 1; i <= n; ++i)
if (i == 1 || fabs(a[i].first - a[i - 1].first) > 0) a[++cnt] = a[i];
else a[cnt].second += a[i].second;
n = cnt;
for (int i = 1; i <= n; ++i) pres[i] = pres[i - 1] + a[i].second;
for (int i = n; i; --i) sufs[i] = sufs[i + 1] + a[i].second;
double ans = 0;
for (int i = 1, p = n; i <= n; ++i) if (i == n || fabs(a[i].first - a[i + 1].first) > 0) {
while (p > 1 && pres[i] / a[i].first > sufs[p] / (1 - a[p].first)) --p;
smax(ans, pres[i] + sufs[p + 1] - pres[i] / a[i].first);
// if (i >= p) break;
smax(ans, pres[i] + sufs[p] - sufs[p] / (1 - a[p].first));
}
cout << fixed << setprecision(10) << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5924kb
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: 5928kb
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: -100
Wrong Answer
time: 1ms
memory: 6000kb
input:
1 0 1
output:
1.0000000000
result:
wrong answer 1st numbers differ - expected: '0.0000000', found: '1.0000000', error = '1.0000000'