QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#353264#968. Extreme WealthHKOI0AC ✓8ms4036kbC++202.7kb2024-03-14 00:08:502024-03-14 00:08:51

Judging History

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

  • [2024-03-14 00:08:51]
  • 评测
  • 测评结果:AC
  • 用时:8ms
  • 内存:4036kb
  • [2024-03-14 00:08:50]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define int long long

typedef long double LD;

LD log_rem(int n) {
    return - (LD) n + logl(n * acosl(-1) * 2) / 2.0L + logl(1.0L + 1.0L / n / 12 + 1.0L / n / n / 288);
}

LD log_factorial(int n){
    return (LD) n * logl(n) - (LD) n + logl(n * acosl(-1) * 2) / 2.0L + logl(1.0L + 1.0L / n / 12 + 1.0L / n / n / 288);
}

LD log_factorial_2(int n){
    LD l = 0, r = 0;
    for (int i = 1; i <= n; i++) {
        LD l2 = l + logl(i);
        r += logl(i) - (l2 - l);
        l = l2;
    }
    l += r;
    return l;
}

LD log_f(int n){
    if (n >= 1e8) {
        return log_factorial(n);
    } else {
        return log_factorial_2(n);
    }
}

LD self_exp(LD x){
    LD res = 0;
    LD v = 1;
    for (int k = 0; k <= 100000; k++) {
        res += v;
        v = v * x / (k + 1);
    }
    return res;
}

void solve(int R, int B) {
    cout << fixed << setprecision(15);
    // cout << log_factorial(1e8) << ' ' << log_factorial_2(1e8) << endl;
    LD l = 0;

    if (R >= 1e7 && B >= 1e7) {
        l -= log_rem(R + B);
        l += log_rem(R);
        l += log_rem(B);

        l += R * logl(R * 2.0L / (R + B));
        l += B * logl(B * 2.0L / (R + B));

        if (l > logl(1e9 + 11) || self_exp(l) > 1e9) {
            cout << "Extreme Wealth" << endl;
        } else {
            cout << self_exp(l) << endl;
        }
        return;
    }

    l += log_f(R + B);
    l -= log_f(R);
    l -= log_f(B);
    l = logl(2) * (R + B) - l;

    if (l > logl(1e9 + 11) || self_exp(l) > 1e9) {
        cout << "Extreme Wealth" << endl;
    } else {
        cout << self_exp(l) << endl;
    }
}

void solve_2(long long r, long long b) {
    vector<vector<double>> dp(r+1,vector<double>(b+1));
    for(int i=0;i<=r;i++)
        for(int j=0;j<=b;j++) {
            if(i==0&&j==0) dp[i][j]=1;
            else if(i==0) dp[i][j]=dp[i][j-1]*2;
            else if(j==0) dp[i][j]=dp[i-1][j]*2;
            else {
                // auto [xmin,xmax]=minmax(dp[i][j-1],dp[i-1][j]);
                // double val=(xmax-xmin)/(xmax+xmin+2);
                // dp[i][j]=()
                double a=dp[i-1][j];
                double b=dp[i][j-1];
                dp[i][j]=2*a*b/(a+b);
            }
        }
    if (isnan(dp[r][b]) || dp[r][b] >= 1e9) {
        cout << "Extreme Wealth" << endl;
        return;
    } else {
        cout << dp[r][b] << endl;
    }
}

signed main() {
#ifndef LOCAL
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    int T = 1;
    int R, B; cin >> R >> B;
    if (true) {
        solve(R, B);
    } else {
        solve_2(R, B);
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3900kb

input:

3 2

output:

3.200000000000000

result:

ok OK 3.20000000, real ans = 3.20000000, error = 0.00000000

Test #2:

score: 0
Accepted
time: 2ms
memory: 3896kb

input:

0 29

output:

536870912.000000000291038

result:

ok OK 536870912.00000000, real ans = 536870912.00000000, error = 0.00000000

Test #3:

score: 0
Accepted
time: 0ms
memory: 3576kb

input:

30 0

output:

Extreme Wealth

result:

ok OK Extreme Wealth, real ans = 1073741824.00000000

Test #4:

score: 0
Accepted
time: 2ms
memory: 3796kb

input:

37 73

output:

5028.488859583218806

result:

ok OK 5028.48885958, real ans = 5028.48885958, error = 0.00000000

Test #5:

score: 0
Accepted
time: 2ms
memory: 3748kb

input:

10000000000 10000000000

output:

177245.385090551602744

result:

ok OK 177245.38509055, real ans = 177245.38509055, error = 0.00000000

Test #6:

score: 0
Accepted
time: 2ms
memory: 3816kb

input:

10000000000 9999412550

output:

989753719.049911452224478

result:

ok OK 989753719.04991150, real ans = 989753719.13242424, error = 0.00000000

Test #7:

score: 0
Accepted
time: 2ms
memory: 3924kb

input:

10000000000 9999412400

output:

994124819.343119634373579

result:

ok OK 994124819.34311962, real ans = 994124819.34340525, error = 0.00000000

Test #8:

score: 0
Accepted
time: 1ms
memory: 3784kb

input:

10000000000 9999412200

output:

999984747.468620802625082

result:

ok OK 999984747.46862078, real ans = 999984746.74201429, error = 0.00000000

Test #9:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

10000000000 9999412199

output:

Extreme Wealth

result:

ok OK Extreme Wealth, real ans = 1000014138.02130949

Test #10:

score: 0
Accepted
time: 1ms
memory: 3828kb

input:

10000000000 9999411862

output:

Extreme Wealth

result:

ok OK Extreme Wealth, real ans = 1009971237.25187039

Test #11:

score: 0
Accepted
time: 1ms
memory: 3768kb

input:

10000000000 9999411861

output:

Extreme Wealth

result:

ok OK Extreme Wealth, real ans = 1010000939.12199187

Test #12:

score: 0
Accepted
time: 1ms
memory: 3604kb

input:

1000000000 100000000

output:

Extreme Wealth

result:

ok OK Extreme Wealth, real ans = 2000288524.07298231

Test #13:

score: 0
Accepted
time: 2ms
memory: 3900kb

input:

999900000 999999999

output:

682861.861643148752819

result:

ok OK 682861.86164315, real ans = 682861.86152047, error = 0.00000000

Test #14:

score: 0
Accepted
time: 8ms
memory: 3796kb

input:

100000 100500

output:

1046.824207523676527

result:

ok OK 1046.82420752, real ans = 1046.82420753, error = 0.00000000

Test #15:

score: 0
Accepted
time: 2ms
memory: 3812kb

input:

1000000000000 1000000000000

output:

1772453.850905516028320

result:

ok OK 1772453.85090552, real ans = 1772453.85090552, error = 0.00000000

Test #16:

score: 0
Accepted
time: 1ms
memory: 3804kb

input:

1000000000000 999995000000

output:

918166982.255485485133249

result:

ok OK 918166982.25548553, real ans = 918167024.49532175, error = 0.00000005

Test #17:

score: 0
Accepted
time: 2ms
memory: 3796kb

input:

1000000000000 999994970000

output:

989900473.983575689431746

result:

ok OK 989900473.98357570, real ans = 989900658.76037264, error = 0.00000019

Test #18:

score: 0
Accepted
time: 2ms
memory: 3808kb

input:

1000000000000 999994969900

output:

990149601.088007989979815

result:

ok OK 990149601.08800805, real ans = 990149653.47589362, error = 0.00000005

Test #19:

score: 0
Accepted
time: 2ms
memory: 3756kb

input:

1000000000000 999994965966

output:

999998916.731033743300941

result:

ok OK 999998916.73103380, real ans = 999998930.01106715, error = 0.00000001

Test #20:

score: 0
Accepted
time: 0ms
memory: 3828kb

input:

1000000000000 999994965965

output:

Extreme Wealth

result:

ok OK Extreme Wealth, real ans = 1000001447.03807712

Test #21:

score: 0
Accepted
time: 1ms
memory: 3556kb

input:

1000000000000 999994962200

output:

Extreme Wealth

result:

ok OK Extreme Wealth, real ans = 1009526689.33672678

Test #22:

score: 0
Accepted
time: 0ms
memory: 3636kb

input:

1000000000000 999994962000

output:

Extreme Wealth

result:

ok OK Extreme Wealth, real ans = 1010035408.79225361

Test #23:

score: 0
Accepted
time: 0ms
memory: 3792kb

input:

10000000000000 10000000000000

output:

5604991.216397928703827

result:

ok OK 5604991.21639793, real ans = 5604991.21639793, error = 0.00000000

Test #24:

score: 0
Accepted
time: 2ms
memory: 3804kb

input:

10000000000000 9999985614000

output:

989882911.580443232611287

result:

ok OK 989882911.58044326, real ans = 989882007.19958651, error = 0.00000091

Test #25:

score: 0
Accepted
time: 2ms
memory: 3800kb

input:

10000000000000 9999985613835

output:

989999538.168199414911214

result:

ok OK 989999538.16819942, real ans = 989999498.61902094, error = 0.00000004

Test #26:

score: 0
Accepted
time: 2ms
memory: 3860kb

input:

10000000000000 9999985613834

output:

989999642.296686753863469

result:

ok OK 989999642.29668677, real ans = 990000210.73484683, error = 0.00000057

Test #27:

score: 0
Accepted
time: 2ms
memory: 3860kb

input:

10000000000000 9999985599900

output:

999978534.913756488589570

result:

ok OK 999978534.91375649, real ans = 999977583.49870884, error = 0.00000095

Test #28:

score: 0
Accepted
time: 1ms
memory: 3640kb

input:

10000000000000 9999985586056

output:

Extreme Wealth

result:

ok OK Extreme Wealth, real ans = 1009999801.48704243

Test #29:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

10000000000000 9999985586055

output:

Extreme Wealth

result:

ok OK Extreme Wealth, real ans = 1010000529.39213884

Test #30:

score: 0
Accepted
time: 0ms
memory: 3828kb

input:

10000000000000 9999985486055

output:

Extreme Wealth

result:

ok OK Extreme Wealth, real ans = 1085749634.67051625

Test #31:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

10000000000000 9999905586055

output:

Extreme Wealth

result:

ok OK Extreme Wealth, real ans = 2000000758.78793645

Test #32:

score: 0
Accepted
time: 0ms
memory: 3576kb

input:

10000000000000 1000000000000

output:

Extreme Wealth

result:

ok OK Extreme Wealth, real ans = 2000003461.21803880

Test #33:

score: 0
Accepted
time: 2ms
memory: 3864kb

input:

0 0

output:

1.000000000000000

result:

ok OK 1.00000000, real ans = 1.00000000, error = 0.00000000

Test #34:

score: 0
Accepted
time: 2ms
memory: 4036kb

input:

0 1

output:

2.000000000000000

result:

ok OK 2.00000000, real ans = 2.00000000, error = 0.00000000

Test #35:

score: 0
Accepted
time: 2ms
memory: 3804kb

input:

1 1

output:

2.000000000000000

result:

ok OK 2.00000000, real ans = 2.00000000, error = 0.00000000

Test #36:

score: 0
Accepted
time: 2ms
memory: 3788kb

input:

0 2

output:

4.000000000000000

result:

ok OK 4.00000000, real ans = 4.00000000, error = 0.00000000

Test #37:

score: 0
Accepted
time: 1ms
memory: 3816kb

input:

1 2

output:

2.666666666666667

result:

ok OK 2.66666667, real ans = 2.66666667, error = 0.00000000

Test #38:

score: 0
Accepted
time: 2ms
memory: 3900kb

input:

2 2

output:

2.666666666666667

result:

ok OK 2.66666667, real ans = 2.66666667, error = 0.00000000

Test #39:

score: 0
Accepted
time: 0ms
memory: 3644kb

input:

10000000000000 0

output:

Extreme Wealth

result:

ok OK Extreme Wealth, real ans = 2147483648.00000000

Test #40:

score: 0
Accepted
time: 0ms
memory: 3832kb

input:

10000000000000 1

output:

Extreme Wealth

result:

ok OK Extreme Wealth, real ans = 3714566310.05405521

Test #41:

score: 0
Accepted
time: 0ms
memory: 3832kb

input:

2 10000000000000

output:

Extreme Wealth

result:

ok OK Extreme Wealth, real ans = 2681735677.50243759