QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#756329 | #8037. Gambler's Ruin | Asda111 | WA | 722ms | 44568kb | C++17 | 2.2kb | 2024-11-16 19:55:30 | 2024-11-16 19:55:31 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
using ll = long long;
#define INF 0x3f3f3f3f
const int N = 1e6 + 10, M = 1e7 + 10;
const double eps = 1e-10;
int n, m;
vector<pair<double, ll>> b, a;
double sx[N], sy[N];
void solve()
{
cin >> n;
int len = 0;
for (int i = 1; i <= n; i++)
{
pair<double, ll> x;
cin >> x.first >> x.second;
b.push_back(x);
}
sort(b.begin(), b.end(), greater());
for (int i = 0; i < n; i++)
{
if (i == 0 || fabs(a[len - 1].first - b[i].first) > eps)
{
a.push_back(b[i]);
len++;
}
else
{
a[len-1].second+=b[i].second;
}
}
// for(int i=0;i<len;i++)
// {
// cout<<a[i].first<<' '<<a[i].second<<endl;
// }
for (int i = 0; i < len; i++)
{
if (i == 0)
sx[i] = a[i].second;
else
sx[i] = sx[i - 1] + a[i].second;
}
for (int i = len - 1; i >= 0; i--)
{
sy[i] = sy[i + 1] + a[i].second;
}
int l = 0, r = len - 1;
double ans = 0;
while (l < r)
{
double x = 1 / a[l].first;
//cout<<x<<endl;
while (x * a[l].first - 1 < 0)
{
x += eps;
//cout<<x<<endl;
}
//ans=max(ans,sx[l]-sx[l]*x);
for (int j = r; j > l; j--)
{
//cout<<j<<endl;
double y = 1 / (1 - a[j].first);
while (y * (1-a[j].first) - 1 < 0)
{
y += eps;
}
if (sx[l] + sy[j] - max(sx[l] * x, sy[j] * y) > ans)
{
ans = sx[l] + sy[j] - max(sx[l] * x, sy[j] * y);
// cout<<ans<<" "<<l<<' '<<j<<endl;
// cout<<sx[l]<<' '<<sy[j]<<' '<<max(sx[l] * x, sy[j] * y)<<endl;
r=j;
}
else
break;
}
l++;
//cout<<l<<' '<<r<<endl;
}
printf("%.10lf", ans);
}
signed main()
{
int _t;
_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: 6000kb
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: 6012kb
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: 1ms
memory: 5892kb
input:
1 0 1
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 6008kb
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: 1ms
memory: 5892kb
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: 1ms
memory: 5888kb
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: 0
Accepted
time: 1ms
memory: 6072kb
input:
3 0.2 100 0.2 100 0.8 100
output:
50.0000000000
result:
ok found '50.0000000', expected '50.0000000', error '0.0000000'
Test #8:
score: 0
Accepted
time: 1ms
memory: 6000kb
input:
2 0.999999 1000000 0.999998 2
output:
0.9999990000
result:
ok found '0.9999990', expected '0.9999990', error '0.0000000'
Test #9:
score: 0
Accepted
time: 1ms
memory: 5892kb
input:
2 0 100000 0.000001 1
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #10:
score: 0
Accepted
time: 1ms
memory: 6064kb
input:
2 0 1000000000 0.000001 1
output:
1.0000000000
result:
ok found '1.0000000', expected '1.0000000', error '0.0000000'
Test #11:
score: -100
Wrong Answer
time: 722ms
memory: 44568kb
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:
770354169567.1662597656
result:
wrong answer 1st numbers differ - expected: '85718080941203.0156250', found: '770354169567.1662598', error = '0.9910129'