QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#648989 | #8037. Gambler's Ruin | Agakiss | WA | 512ms | 37328kb | C++20 | 2.9kb | 2024-10-17 21:12:13 | 2024-10-17 21:12:14 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define DEBUG
#ifdef DEBUG
#define debug(...) [](auto...a){((cout<<a<<' '),...)<<endl;}(#__VA_ARGS__,":",__VA_ARGS__)
#define debugv(v) do{cout<<#v<<" : {";for(int izxc=0;izxc<v.size();++izxc){cout<<v[izxc];if(izxc+1!=v.size())cout <<", ";}cout<<"}"<<endl;}while(0)
#define debugmp(mp) do{cout<<#mp<<" : { ";for(auto p:mp){cout<<'['<<p.first<<" -> "<<p.second<<"] ";}cout<<"}"<<endl;}while(0)
#define debugset(s) do{cout<<#s<<" : {";for(auto x:s)cout<<x<<' ';cout<<"}"<<endl;}while(0)
#else
#define debug(...)
#define debugv(v)
#define debugmp(mp)
#define debugset(s)
#endif
typedef long long i64;
typedef pair<int, int> pii;
const int N = 1e6 + 10;
i64 n, cnt, c[N], pre[N], suf[N];
double p[N], ans; int t[N];
int m[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) {
double P;
int C;
cin >> P >> C;
if (!m[(int)(P * 1e6)]) m[(int)(P * 1e6)] = ++cnt;
p[m[(int)(P * 1e6)]] = P, c[m[(int)(P * 1e6)]] += C;
}
n = cnt;
iota(t + 1, t + n + 1, 1);
sort(t + 1, t + n + 1, [](int A, int B){return p[A] > p[B];});
for(int i = 1; i <= n; i++) pre[i] = pre[i - 1] + c[t[i]];
for(int i = n; i >= 1; i--) suf[i] = suf[i + 1] + c[t[i]];
sort(p + 1, p + n + 1, [](double A, double B){return A > B;});
//for(int i = 1; i <= n; i++) debug(i, p[i], pre[i], suf[i]);
for(int i = 1, j = n + 1; i <= n; i++) {
if(p[i] < 1e-8) break;
while(i < n && fabs(p[i] - p[i + 1]) < 1e-8) i++;
double x = 1.00 / p[i];
if(j <= i) j = i + 1;
while(j - 1 > i && x * pre[i] + 1e-8 > suf[j - 1] * (1.00 / (1.00 - p[j - 1]))) j--;
double y = 1.00 / (1.00 - p[j]);
ans = max(ans, pre[i] + suf[j] - max(pre[i] * x, suf[j] * y));
//if (j > i + 1) {
j--;
y = 1.00 / (1.00 - p[j]);
ans = max(ans, pre[i] + suf[j] - max(pre[i] * x, suf[j] * y));
j--;
y = 1.00 / (1.00 - p[j]);
ans = max(ans, pre[i] + suf[j] - max(pre[i] * x, suf[j] * y));
j--;
y = 1.00 / (1.00 - p[j]);
ans = max(ans, pre[i] + suf[j] - max(pre[i] * x, suf[j] * y)); j--;
y = 1.00 / (1.00 - p[j]);
ans = max(ans, pre[i] + suf[j] - max(pre[i] * x, suf[j] * y));
j--;
y = 1.00 / (1.00 - p[j]);
ans = max(ans, pre[i] + suf[j] - max(pre[i] * x, suf[j] * y));
j--;
y = 1.00 / (1.00 - p[j]);
ans = max(ans, pre[i] + suf[j] - max(pre[i] * x, suf[j] * y));
//}
//debug(i, pre[i], j, suf[j], x, y);
//std::cout << ans << endl;
}
cout << fixed << setprecision(15) << ans << endl;
return 0;
}
/*
3
0.2 100
0.2 100
0.8 100
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 8024kb
input:
2 1 15 0 10
output:
10.000000000000000
result:
ok found '10.0000000', expected '10.0000000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 1ms
memory: 7844kb
input:
3 0.4 100 0.5 100 0.6 100
output:
33.333333333333314
result:
ok found '33.3333333', expected '33.3333333', error '0.0000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 10032kb
input:
1 0 1
output:
0.000000000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #4:
score: 0
Accepted
time: 0ms
memory: 8016kb
input:
2 1 0 1 100
output:
0.000000000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #5:
score: 0
Accepted
time: 0ms
memory: 8084kb
input:
1 0.5 100
output:
0.000000000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #6:
score: 0
Accepted
time: 2ms
memory: 10024kb
input:
3 0.4 100 0.6 100 0.6 100
output:
0.000000000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #7:
score: 0
Accepted
time: 0ms
memory: 7964kb
input:
3 0.2 100 0.2 100 0.8 100
output:
50.000000000000000
result:
ok found '50.0000000', expected '50.0000000', error '0.0000000'
Test #8:
score: 0
Accepted
time: 1ms
memory: 8016kb
input:
2 0.999999 1000000 0.999998 2
output:
0.999998999992386
result:
ok found '0.9999990', expected '0.9999990', error '0.0000000'
Test #9:
score: 0
Accepted
time: 0ms
memory: 10060kb
input:
2 0 100000 0.000001 1
output:
0.000000000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #10:
score: 0
Accepted
time: 2ms
memory: 10128kb
input:
2 0 1000000000 0.000001 1
output:
1.000000000000000
result:
ok found '1.0000000', expected '1.0000000', error '0.0000000'
Test #11:
score: -100
Wrong Answer
time: 512ms
memory: 37328kb
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:
3067138276946.445312500000000
result:
wrong answer 1st numbers differ - expected: '85718080941203.0156250', found: '3067138276946.4453125', error = '0.9642183'