結果

問題 No.108 トリプルカードコンプ
ユーザー nebukuro09nebukuro09
提出日時 2016-11-12 11:47:43
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 41 ms / 5,000 ms
コード長 931 bytes
コンパイル時間 1,965 ms
コンパイル使用メモリ 157,964 KB
実行使用メモリ 13,284 KB
最終ジャッジ日時 2023-09-02 22:53:23
合計ジャッジ時間 3,534 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 1 ms
4,368 KB
testcase_04 AC 1 ms
4,368 KB
testcase_05 AC 1 ms
4,372 KB
testcase_06 AC 1 ms
4,368 KB
testcase_07 AC 41 ms
12,804 KB
testcase_08 AC 41 ms
12,540 KB
testcase_09 AC 41 ms
12,224 KB
testcase_10 AC 41 ms
12,028 KB
testcase_11 AC 41 ms
13,284 KB
testcase_12 AC 1 ms
4,368 KB
testcase_13 AC 6 ms
4,368 KB
testcase_14 AC 6 ms
4,372 KB
testcase_15 AC 6 ms
4,368 KB
testcase_16 AC 6 ms
4,372 KB
testcase_17 AC 5 ms
4,372 KB
testcase_18 AC 37 ms
11,012 KB
testcase_19 AC 35 ms
11,032 KB
testcase_20 AC 41 ms
12,292 KB
testcase_21 AC 40 ms
11,324 KB
testcase_22 AC 34 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio;
import std.array;
import std.string;
import std.conv;
import std.algorithm;
import std.typecons;
import std.range;
import std.random;
import std.math;
import std.container;
import std.numeric;

void main() {
  int N = readln.chomp.to!int;
  auto A = readln.split.map!(to!int);

  auto dp = new double[][][](N+1, N+1, N+1);
  dp[0][0][0] = 0.0;

  foreach (i; iota(N+1))
    foreach (j; iota(N+1))
      foreach (k; iota(N+1)) {
        if (i+j+k == 0)
          continue;
        dp[i][j][k] = N*1.0/(i+j+k);
        if (k-1 >= 0)
          dp[i][j][k] += dp[i][j][k-1] * (k*1.0/(i+j+k));
        if (j-1 >= 0 && k+1 <= N)
          dp[i][j][k] += dp[i][j-1][k+1] * (j*1.0/(i+j+k));
        if (i-1 >= 0 && j+1 <= N)
          dp[i][j][k] += dp[i-1][j+1][k] * (i*1.0/(i+j+k));
      }
            
  int[4] count;
  foreach (a; A)
    count[min(a, 3)] += 1;
  writef("%.07f", dp[count[0]][count[1]][count[2]]);
}
0