QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#353257#968. Extreme WealthHKOI0WA 7ms3956kbC++202.0kb2024-03-13 23:52:072024-03-13 23:52:09

Judging History

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

  • [2024-03-13 23:52:09]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:3956kb
  • [2024-03-13 23:52:07]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define int long long

typedef long double LD;

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);
    }
}

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

    if (l > logl(1e9 + 11) || expl(l) > 1e9) {
        cout << "Extreme Wealth" << endl;
    } else {
        cout << expl(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: 1ms
memory: 3808kb

input:

3 2

output:

3.200000000000000

result:

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

Test #2:

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

input:

0 29

output:

536870912.000000000640284

result:

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

Test #3:

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

input:

30 0

output:

Extreme Wealth

result:

ok OK Extreme Wealth, real ans = 1073741824.00000000

Test #4:

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

input:

37 73

output:

5028.488859583218807

result:

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

Test #5:

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

input:

10000000000 10000000000

output:

177245.384076542715405

result:

ok OK 177245.38407654, real ans = 177245.38509055, error = 0.00000001

Test #6:

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

input:

10000000000 9999412550

output:

989753698.283222501981072

result:

ok OK 989753698.28322256, real ans = 989753719.13242424, error = 0.00000002

Test #7:

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

input:

10000000000 9999412400

output:

994124831.078663951833732

result:

ok OK 994124831.07866395, real ans = 994124819.34340525, error = 0.00000001

Test #8:

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

input:

10000000000 9999412200

output:

999984760.885083143366501

result:

ok OK 999984760.88508320, real ans = 999984746.74201429, error = 0.00000001

Test #9:

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

input:

10000000000 9999412199

output:

Extreme Wealth

result:

ok OK Extreme Wealth, real ans = 1000014138.02130949

Test #10:

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

input:

10000000000 9999411862

output:

Extreme Wealth

result:

ok OK Extreme Wealth, real ans = 1009971237.25187039

Test #11:

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

input:

10000000000 9999411861

output:

Extreme Wealth

result:

ok OK Extreme Wealth, real ans = 1010000939.12199187

Test #12:

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

input:

1000000000 100000000

output:

Extreme Wealth

result:

ok OK Extreme Wealth, real ans = 2000288524.07298231

Test #13:

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

input:

999900000 999999999

output:

682861.859692115396626

result:

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

Test #14:

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

input:

100000 100500

output:

1046.824207523557518

result:

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

Test #15:

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

input:

1000000000000 1000000000000

output:

1772452.259920653610152

result:

ok OK 1772452.25992065, real ans = 1772453.85090552, error = 0.00000090

Test #16:

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

input:

1000000000000 999995000000

output:

918170514.297022277663928

result:

wrong answer WA 918170514.29702222, real ans = 918167024.49532175, error = 0.00000380