結果

問題 No.1688 Veterinarian
ユーザー 👑 jupirojupiro
提出日時 2021-09-24 21:47:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 3,000 ms
コード長 2,320 bytes
コンパイル時間 4,849 ms
コンパイル使用メモリ 215,456 KB
実行使用メモリ 9,712 KB
最終ジャッジ日時 2023-09-18 21:07:32
合計ジャッジ時間 4,045 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using ll = long long;
using std::cin;
using std::cout;
using std::endl;
std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

void solve([[maybe_unused]] int CASE)
{
  int a, b, c, n; cin >> a >> b >> c >> n;
  using real = long double;
  std::vector dp(a + 1, std::vector(b + 1, std::vector<real>(c + 1, 0.0)));
  auto ndp = dp;
  auto ini = dp;
  dp[a][b][c] = 1.0;
  for (int kkt = 0; kkt < n; ++kkt)
  {
    ndp = ini;
    for (int i = 0; i <= a; ++i)
    {
      for (int j = 0; j <= b; ++j)
      {
        for (int k = 0; k <= c; ++k)
        {
          if(dp[i][j][k] == 0)
            continue;
          const int all = i + j + k;
          const int allC = all * (all - 1) / 2;
          double s_prob = 0;
          if(i >= 2)
          {
            const double prob = (real)(i * (i - 1) / 2) / (real)allC;
            ndp[i - 1][j][k] += dp[i][j][k] * prob;
            s_prob += prob;
          }
          if(j >= 2)
          {
            const double prob = (real)(j * (j - 1) / 2) / (real)allC;
            ndp[i][j - 1][k] += dp[i][j][k] * prob;
            s_prob += prob;
          }
          if(k >= 2)
          {
            const double prob = (real)(k * (k - 1) / 2) / (real)allC;
            ndp[i][j][k - 1] += dp[i][j][k] * prob;
            s_prob += prob;
          }
          ndp[i][j][k] += dp[i][j][k] * (1 - s_prob);
        }
      }
    }
    std::swap(dp, ndp);
  }
  real res_a = 0, res_b = 0, res_c = 0;
  for (int i = 0; i <= a; ++i)
  {
    for (int j = 0; j <= b; ++j)
    {
      for (int k = 0; k <= c; ++k)
      {
        res_a += (a - i) * dp[i][j][k];
        res_b += (b - j) * dp[i][j][k];
        res_c += (c - k) * dp[i][j][k];
      }
    }
  }

  cout << std::fixed << std::setprecision(15) << res_a << " " << res_b << " " << res_c << endl;
}

int main()
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int kkt = 1;
  // cin >> kkt;
  for (int jupi = 1; jupi <= kkt; jupi++)
    solve(jupi);
  return 0;
}
0