結果

問題 No.1688 Veterinarian
ユーザー tokusakuraitokusakurai
提出日時 2021-09-24 21:38:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 157 ms / 3,000 ms
コード長 2,184 bytes
コンパイル時間 2,137 ms
コンパイル使用メモリ 201,488 KB
実行使用メモリ 162,208 KB
最終ジャッジ日時 2023-09-18 20:56:17
合計ジャッジ時間 3,201 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 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,384 KB
testcase_07 AC 8 ms
9,792 KB
testcase_08 AC 157 ms
162,208 KB
testcase_09 AC 88 ms
150,052 KB
testcase_10 AC 11 ms
15,692 KB
testcase_11 AC 13 ms
18,792 KB
testcase_12 AC 3 ms
4,600 KB
testcase_13 AC 3 ms
4,800 KB
testcase_14 AC 4 ms
5,756 KB
testcase_15 AC 10 ms
12,096 KB
testcase_16 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, x, n) for (int i = x; i <= n; i++)
#define rep3(i, x, n) for (int i = x; i >= n; i--)
#define each(e, v) for (auto &e : v)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int inf = (1 << 30) - 1;
const ll INF = (1LL << 60) - 1;
template <typename T>
bool chmax(T &x, const T &y) {
    return (x < y) ? (x = y, true) : false;
}
template <typename T>
bool chmin(T &x, const T &y) {
    return (x > y) ? (x = y, true) : false;
}

struct io_setup {
    io_setup() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;

int main() {
    int A, B, C, N;
    cin >> A >> B >> C >> N;

    double dp1[N + 1][A + 1][B + 1][C + 1], dp2[N + 1][A + 1][B + 1][C + 1], dp3[N + 1][A + 1][B + 1][C + 1];

    rep(i, N + 1) {
        rep(j, A + 1) rep(k, B + 1) rep(l, C + 1) {
            if (i == 0 || j * k * l == 0) {
                dp1[i][j][k][l] = 0;
                dp2[i][j][k][l] = 0;
                dp3[i][j][k][l] = 0;
                continue;
            }
            double S = (j + k + l) * (j + k + l - 1) / 2;
            double a = j * (j - 1) / 2, b = k * (k - 1) / 2, c = l * (l - 1) / 2;
            double x = S - a - b - c;
            dp1[i][j][k][l] = (x * dp1[i - 1][j][k][l] + a * (dp1[i - 1][j - 1][k][l] + 1) + b * dp1[i - 1][j][k - 1][l] + c * dp1[i - 1][j][k][l - 1]) / S;
            dp2[i][j][k][l] = (x * dp2[i - 1][j][k][l] + a * dp2[i - 1][j - 1][k][l] + b * (dp2[i - 1][j][k - 1][l] + 1) + c * dp2[i - 1][j][k][l - 1]) / S;
            dp3[i][j][k][l] = (x * dp3[i - 1][j][k][l] + a * dp3[i - 1][j - 1][k][l] + b * dp3[i - 1][j][k - 1][l] + c * (dp3[i - 1][j][k][l - 1] + 1)) / S;
        }
    }

    cout << dp1[N][A][B][C] << ' ' << dp2[N][A][B][C] << ' ' << dp3[N][A][B][C] << '\n';
}
0