結果

問題 No.1688 Veterinarian
ユーザー batsumarubatsumaru
提出日時 2021-09-24 22:05:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 331 ms / 3,000 ms
コード長 1,433 bytes
コンパイル時間 1,452 ms
コンパイル使用メモリ 166,600 KB
実行使用メモリ 56,516 KB
最終ジャッジ日時 2023-09-18 21:23:25
合計ジャッジ時間 3,010 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 12 ms
52,700 KB
testcase_02 AC 4 ms
15,964 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 12 ms
52,824 KB
testcase_07 AC 9 ms
7,776 KB
testcase_08 AC 331 ms
56,516 KB
testcase_09 AC 301 ms
55,404 KB
testcase_10 AC 27 ms
36,832 KB
testcase_11 AC 28 ms
26,592 KB
testcase_12 AC 3 ms
6,312 KB
testcase_13 AC 9 ms
30,436 KB
testcase_14 AC 6 ms
9,964 KB
testcase_15 AC 26 ms
50,952 KB
testcase_16 AC 4 ms
11,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

ll a, b, c, n;
double dp[51][51][51][51];

double calc(ll l, ll i, ll j, ll k) {
  if (dp[l][i][j][k] >= -0.1) {
    return dp[l][i][j][k];
  }
  double res = 0.0;
  ll s = i + j + k;
  if (s > 1) {
    res += calc(l - 1, i, j, k) * (i * j + j * k + k * i) * 2 / (s * (s - 1));
  }
  if (s > 0) {
    res += calc(l - 1, i + 1, j, k) * (i + 1) * i / (s * (s + 1));
    res += calc(l - 1, i, j + 1, k) * (j + 1) * j / (s * (s + 1));
    res += calc(l - 1, i, j, k + 1) * (k + 1) * k / (s * (s + 1));
  }
  return dp[l][i][j][k] = res;
}

int main() {
  cin >> a >> b >> c >> n;
  REP(i, a + 1) REP(j, b + 1) REP(k, c + 1) REP(l, n + 1) {
    dp[l][i][j][k] = -1;
    dp[0][i][j][k] = 0.0;
  }
  dp[0][a][b][c] = 1.0;

  vector<double> ans(3);
  REP(i, a + 1) REP(j, b + 1) REP(k, c + 1) {
    if (i + j + k == 0) {
      continue;
    }
    ans[0] += calc(n, i, j, k) * (a - i);
    ans[1] += calc(n, i, j, k) * (b - j);
    ans[2] += calc(n, i, j, k) * (c - k);
  }

  cout << fixed << setprecision(10);
  REP(i, 3) { cout << ans[i] << " \n"[i + 1 == 3]; }
}
0