結果

問題 No.1688 Veterinarian
ユーザー sten_sansten_san
提出日時 2021-09-24 21:57:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 128 ms / 3,000 ms
コード長 2,613 bytes
コンパイル時間 2,194 ms
コンパイル使用メモリ 209,544 KB
実行使用メモリ 61,080 KB
最終ジャッジ日時 2023-09-18 21:18:19
合計ジャッジ時間 3,285 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 7 ms
6,436 KB
testcase_08 AC 128 ms
61,080 KB
testcase_09 AC 119 ms
56,852 KB
testcase_10 AC 12 ms
8,260 KB
testcase_11 AC 14 ms
9,228 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 3 ms
4,384 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 8 ms
6,172 KB
testcase_16 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct iofast_t {
    iofast_t() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} iofast;

struct uns_t {} uns;
template <typename Element, typename Head, typename ...Args>
auto vec(Element init, Head arg, Args ...args) {
    if constexpr (sizeof...(Args) == 0) return std::vector(arg, init);
    else return std::vector(arg, vec(init, args...));
}
template <typename Element, typename Head, typename ...Args>
auto vec(uns_t, Head arg, Args ...args) {
    return vec(Element(), arg, args...);
}

template <typename T, typename Compare = less<T>>
T &chmin(T &l, T r, Compare &&f = less<T>()) { return l = min(l, r, f); }
template <typename T, typename Compare = less<T>>
T &chmax(T &l, T r, Compare &&f = less<T>()) { return l = max(l, r, f); }

int main() {
    cout << fixed << setprecision(15);

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

    auto dp = vec<double>(0, n + 1, a + 1, b + 1, c + 1);

    dp[0][0][0][0] = 1;
    for (int i = 1; i <= n; ++i) {
        for (int x = 0; x <= a; ++x) {
            for (int y = 0; y <= b; ++y) {
                for (int z = 0; z <= c; ++z) {
                    int p = a - x;
                    int q = b - y;
                    int r = c - z;

                    if (0 < (p + q + r) * (p + q + r - 1) / 2) {
                        dp[i][x][y][z] =
                            dp[i - 1][x][y][z] *
                            (p * q + p * r + q * r) / ((p + q + r) * (p + q + r - 1) / 2);
                    }

                    if ((p + q + r) * (p + q + r + 1) <= 0) {
                        continue;
                    }

                    if (0 <= x - 1) {
                        dp[i][x][y][z] += dp[i - 1][x - 1][y][z] * (p * (p + 1)) / ((p + q + r) * (p + q + r + 1));
                    }
                    if (0 <= y - 1) {
                        dp[i][x][y][z] += dp[i - 1][x][y - 1][z] * (q * (q + 1)) / ((p + q + r) * (p + q + r + 1));
                    }
                    if (0 <= z - 1) {
                        dp[i][x][y][z] += dp[i - 1][x][y][z - 1] * (r * (r + 1)) / ((p + q + r) * (p + q + r + 1));
                    }
                }
            }
        }
    }

    double ans1 = 0, ans2 = 0, ans3 = 0;
    for (int i = 0; i <= a; ++i) {
        for (int j = 0; j <= b; ++j) {
            for (int k = 0; k <= c; ++k) {
                ans1 += i * dp[n][i][j][k];
                ans2 += j * dp[n][i][j][k];
                ans3 += k * dp[n][i][j][k];
            }
        }
    }

    cout << ans1 << ' ' << ans2 << ' ' << ans3 << endl;
}

0