結果

問題 No.1688 Veterinarian
ユーザー nebukuro09nebukuro09
提出日時 2021-09-24 21:58:35
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 195 ms / 3,000 ms
コード長 1,567 bytes
コンパイル時間 1,846 ms
コンパイル使用メモリ 155,872 KB
実行使用メモリ 142,932 KB
最終ジャッジ日時 2023-09-04 14:12:46
合計ジャッジ時間 4,075 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,388 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 10 ms
8,436 KB
testcase_08 AC 195 ms
142,932 KB
testcase_09 AC 175 ms
131,836 KB
testcase_10 AC 19 ms
13,016 KB
testcase_11 AC 18 ms
15,072 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 4 ms
4,384 KB
testcase_14 AC 4 ms
5,040 KB
testcase_15 AC 16 ms
11,064 KB
testcase_16 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

immutable long MOD = 10^^9 + 7;

void main() {
    auto s = readln.split.map!(to!int);
    auto A = s[0];
    auto B = s[1];
    auto C = s[2];
    auto N = s[3];

    auto dp = new real[][][][](N+1, A+1, B+1, C+1);
    foreach (i; 0..N+1) foreach (a; 0..A+1) foreach (b; 0..B+1) dp[i][a][b][] = 0;
    dp[0][0][0][0] = 1;

    foreach (i; 0..N) foreach (a; 0..A+1) foreach (b; 0..B+1) foreach (c; 0..C+1) {
        auto p = dp[i][a][b][c];
        auto sm = A + B + C - (a + b + c);
        real hoge = 1;
        if (p == 0) continue;
        if (A - a >= 2) {
            auto x = 1.0L * (A - a) / sm * (A - a - 1) / (sm - 1);
            dp[i+1][a+1][b][c] += p * x;
            hoge -= x;
        }
        if (B - b >= 2) {
            auto x = 1.0L * (B - b) / sm * (B - b - 1) / (sm - 1);
            dp[i+1][a][b+1][c] += p * x;
            hoge -= x;
        }
        if (C - c >= 2) {
            auto x = 1.0L * (C - c) / sm * (C - c - 1) / (sm - 1);
            dp[i+1][a][b][c+1] += p * x;
            hoge -= x;
        }
        dp[i+1][a][b][c] += p * hoge;
    }

    real ans_a = 0;
    real ans_b = 0;
    real ans_c = 0;

    foreach (a; 0..A+1) foreach (b; 0..B+1) foreach (c; 0..C+1) {
        auto p = dp[N][a][b][c];
        ans_a += a * p;
        ans_b += b * p;
        ans_c += c * p;
    }

    writeln(format("%.15f %.15f %.15f", ans_a, ans_b, ans_c));
}
0