QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#744008 | #8037. Gambler's Ruin | ucup-team3548# | WA | 329ms | 36608kb | C++20 | 1.6kb | 2024-11-13 20:34:39 | 2024-11-13 20:34:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 2e9 + 7;
const double eps = 1e-8;
void solve() {
int n;
cin >> n;
vector<pair<double, int> > a(n);
for (auto &[p, c] : a) {
cin >> p >> c;
}
sort(a.begin(), a.end());
reverse(a.begin(), a.end());
vector<pair<double, int> > b;
for (int i = 0; i < n; ) {
b.push_back(a[i]);
i++;
while (i < n && b.back().first == a[i].first) {
b.back().second += a[i].second;
i++;
}
}
swap(a, b);
n = a.size();
ll sum1 = 0, sum2 = 0;
double ans = 0;
double y = 0;
for (int i = 0, j = n - 1; i < n; ++i) {
double x = 1 / a[i].first;
sum1 += a[i].second;
while (i < j && a[j].first != 1 && (1 / (1 - a[j].first) * (sum2 + a[j].second) <= sum1 * x || fabs(1 / (1 - a[j].first) * (sum2 + a[j].second) - sum1 * x) < eps)) {
sum2 += a[j].second;
y = 1 / (1 - a[j].first);
j--;
}
// if (y != 0) {
ans = max(ans, sum1 + sum2 - max(sum1 * x, sum2 * y));
// }
if (i < j) {
double z = 1 / (1 - a[j].first);
ans = max(ans, sum1 + sum2 + a[j].second - max(sum1 * x, (sum2 + a[j].second) * z));
} else {
break;
}
}
cout << fixed << setprecision(12) << ans << "\n";
}
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4012kb
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: 3840kb
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: 3876kb
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: 3788kb
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: 3876kb
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: 3772kb
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: 4000kb
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: 3772kb
input:
2 0.999999 1000000 0.999998 2
output:
0.999998999992
result:
ok found '0.9999990', expected '0.9999990', error '0.0000000'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3720kb
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: 3776kb
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: 329ms
memory: 36608kb
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:
74599896415843.281250000000
result:
wrong answer 1st numbers differ - expected: '85718080941203.0156250', found: '74599896415843.2812500', error = '0.1297064'