結果

問題 No.1688 Veterinarian
コンテスト
ユーザー siman
提出日時 2022-06-08 07:27:12
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 52 ms / 3,000 ms
コード長 1,519 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 7,588 ms
コンパイル使用メモリ 147,708 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2026-04-09 12:21:38
合計ジャッジ時間 5,202 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:20:27: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   20 |   double dp[A + 1][B + 1][C + 1];
      |                           ^~~~~
main.cpp:20:27: note: read of non-const variable 'C' is not allowed in a constant expression
main.cpp:17:13: note: declared here
   17 |   int A, B, C, N;
      |             ^
main.cpp:20:20: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   20 |   double dp[A + 1][B + 1][C + 1];
      |                    ^~~~~
main.cpp:20:20: note: read of non-const variable 'B' is not allowed in a constant expression
main.cpp:17:10: note: declared here
   17 |   int A, B, C, N;
      |          ^
main.cpp:20:13: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   20 |   double dp[A + 1][B + 1][C + 1];
      |             ^~~~~
main.cpp:20:13: note: read of non-const variable 'A' is not allowed in a constant expression
main.cpp:17:7: note: declared here
   17 |   int A, B, C, N;
      |       ^
main.cpp:25:30: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   25 |     double tmp[A + 1][B + 1][C + 1];
      |                              ^~~~~
main.cpp:25:30: note: read of non-const variable 'C' is not allowed in a constant expression
main.cpp:17:13: note: declared here
   17 |   int A, B, C, N;
      |             ^
main.cpp:25:23: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   25 |     double tmp[A + 1][B + 1][C + 1];
      |                       ^~~~~
main.cpp:25:23: note: read of non-const variable 'B' is not allowed in a constant expression
main.cpp:17:10: note: declared here
   17 |   int A, B, C, N;
      |          ^
main.cpp:25:16: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   25 |     double tmp[A + 1][B + 1][C + 1];
      |                ^~~~~
main.cpp:25:16: note: read of non-const variable 'A' is not allowe

ソースコード

diff #
raw source code

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

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

  double dp[A + 1][B + 1][C + 1];
  memset(dp, 0, sizeof(dp));
  dp[A][B][C] = 1.0;

  for (int i = 0; i < N; ++i) {
    double tmp[A + 1][B + 1][C + 1];
    memset(tmp, 0, sizeof(tmp));

    for (int a = 1; a <= A; ++a) {
      for (int b = 1; b <= B; ++b) {
        for (int c = 1; c <= C; ++c) {
          int S = a + b + c;

          double pa = a * (a - 1) * 1.0 / (S * (S - 1));
          double pb = b * (b - 1) * 1.0 / (S * (S - 1));
          double pc = c * (c - 1) * 1.0 / (S * (S - 1));

          tmp[a - 1][b][c] += pa * dp[a][b][c];
          tmp[a][b - 1][c] += pb * dp[a][b][c];
          tmp[a][b][c - 1] += pc * dp[a][b][c];
          tmp[a][b][c] += (1.0 - pa - pb - pc) * dp[a][b][c];
        }
      }
    }

    memcpy(dp, tmp, sizeof(tmp));
  }

  double ans[3] = {0.0, 0.0, 0.0};

  for (int a = 1; a <= A; ++a) {
    for (int b = 1; b <= B; ++b) {
      for (int c = 1; c <= C; ++c) {
        int da = A - a;
        int db = B - b;
        int dc = C - c;

        ans[0] += da * dp[a][b][c];
        ans[1] += db * dp[a][b][c];
        ans[2] += dc * dp[a][b][c];
      }
    }
  }

  cout << fixed << setprecision(10) << ans[0] << " " << ans[1] << " " << ans[2] << endl;

  return 0;
}
0