QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#756294#8037. Gambler's RuinAsda111WA 0ms3972kbC++171.8kb2024-11-16 19:46:232024-11-16 19:46:24

Judging History

你现在查看的是最新测评结果

  • [2024-11-16 19:46:24]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3972kb
  • [2024-11-16 19:46:23]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
using ll = long long;
#define INF 0x3f3f3f3f
const int N = 1e5 + 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++;
        }
    }
    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;
        }
        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);
                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: 0ms
memory: 3956kb

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: 3968kb

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: 3972kb

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: 3856kb

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: 3856kb

input:

1
0.5 100

output:

0.0000000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 3900kb

input:

3
0.4 100
0.6 100
0.6 100

output:

33.3333333333

result:

wrong answer 1st numbers differ - expected: '0.0000000', found: '33.3333333', error = '33.3333333'