QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#353235#968. Extreme WealthHKOI0RE 1ms4036kbC++202.0kb2024-03-13 23:42:132024-03-13 23:42:14

Judging History

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

  • [2024-03-13 23:42:14]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:4036kb
  • [2024-03-13 23:42:13]
  • 提交

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 (false) {
        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: 4028kb

input:

3 2

output:

3.2

result:

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

Test #2:

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

input:

0 29

output:

5.36871e+08

result:

ok OK 536871000.00000000, real ans = 536870912.00000000, error = 0.00000016

Test #3:

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

input:

30 0

output:

Extreme Wealth

result:

ok OK Extreme Wealth, real ans = 1073741824.00000000

Test #4:

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

input:

37 73

output:

5028.49

result:

ok OK 5028.49000000, real ans = 5028.48885958, error = 0.00000023

Test #5:

score: -100
Runtime Error

input:

10000000000 10000000000

output:


result: