結果

問題 No.1688 Veterinarian
ユーザー monkukui2monkukui2
提出日時 2021-09-24 21:59:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 3,000 ms
コード長 3,561 bytes
コンパイル時間 1,009 ms
コンパイル使用メモリ 105,976 KB
実行使用メモリ 5,412 KB
最終ジャッジ日時 2023-09-18 21:19:17
合計ジャッジ時間 1,867 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 4 ms
5,412 KB
testcase_08 AC 37 ms
5,192 KB
testcase_09 AC 34 ms
5,412 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "atcoder/modint.hpp"
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>
#include <cstddef>
#include <type_traits>
#include <vector>

using namespace std;
const long long int INF = numeric_limits<long long int>::max() / 4;
const int inf = numeric_limits<int>::max() / 4;
const long long int MOD1000000007 = 1000000007;
const long long int MOD998244353 = 998244353;
const double MATH_PI = 3.1415926535897932;

template<typename T1, typename T2>
inline void chmin(T1 &a, const T2 &b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, const T2 &b) { if (a < b) a = b; }

#define lint long long int
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define VI vector<int>
#define VLL vector<long long>
#define VC vector<char>
#define VB vector<bool>
#define PI pair<int, int>
#define PLL pair<long long, long long>
#define VPI vector<pair<int, int>>
#define VPLL vector<pair<long long, long long>>
#define VVI vector<vector<int>>
#define VVPI vecor<vector<pair<int, int>>>
#define VVPILL vector<vector<pair<int, long long>>>

#define SUM(v) accumulate(ALL(v), 0LL)
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))

using mint = atcoder::modint998244353;

int main() {

    int a, b, c, n; cin >> a >> b >> c >> n;

    vector<vector<vector<double>>> dp(a + 1, vector<vector<double>>(b + 1, vector<double>(c + 1, 0.0)));
    dp[a][b][c] = 1.0;
    for (int i = 0; i < n; i++) {
        vector<vector<vector<double>>> ndp(a + 1, vector<vector<double>>(b + 1, vector<double>(c + 1, 0.0)));
        for (int ia = 0; ia <= a; ia++) {
            for (int ib = 0; ib <= b; ib++) {
                for (int ic = 0; ic <= c; ic++) {
                    if (dp[ia][ib][ic] == 0.0) continue;
                    int total = ia + ib + ic;
                    double yo = 1.0;
                    if (ia >= 1) {
                        double p = (double) ia * (ia - 1) / ((double) total * (total - 1));
                        yo -= p;
                        ndp[ia - 1][ib][ic] += dp[ia][ib][ic] * p;
                    }
                    if (ib >= 1) {
                        double p = (double) ib * (ib - 1) / ((double) total * (total - 1));
                        yo -= p;
                        ndp[ia][ib - 1][ic] += dp[ia][ib][ic] * p;
                    }
                    if (ic >= 1) {
                        double p = (double) ic * (ic - 1) / ((double) total * (total - 1));
                        yo -= p;
                        ndp[ia][ib][ic - 1] += dp[ia][ib][ic] * p;
                    }
                    ndp[ia][ib][ic] += dp[ia][ib][ic] * yo;
                }
            }
        }
        swap(dp, ndp);
    }

    double ansa = 0.0;
    double ansb = 0.0;
    double ansc = 0.0;
    for (int ia = 0; ia <= a; ia++) {
        for (int ib = 0; ib <= b; ib++) {
            for (int ic = 0; ic <= c; ic++) {
                ansa += (a - ia) * dp[ia][ib][ic];
                ansb += (b - ib) * dp[ia][ib][ic];
                ansc += (c - ic) * dp[ia][ib][ic];
            }
        }
    }
    printf("%.10f %.10f %.10f", ansa, ansb, ansc);
    return 0;
}
0