結果

問題 No.108 トリプルカードコンプ
ユーザー hytkxdhytkxd
提出日時 2023-09-01 16:44:53
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 744 bytes
コンパイル時間 708 ms
コンパイル使用メモリ 11,348 KB
実行使用メモリ 90,036 KB
最終ジャッジ日時 2023-09-01 16:45:02
合計ジャッジ時間 8,030 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
15,364 KB
testcase_01 AC 74 ms
15,052 KB
testcase_02 AC 77 ms
15,204 KB
testcase_03 AC 76 ms
15,152 KB
testcase_04 AC 75 ms
15,068 KB
testcase_05 AC 76 ms
15,128 KB
testcase_06 AC 74 ms
14,980 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/usr/local/bin/ruby
class TripleCardComp
  def initialize(*arg)
    @n,@a = arg
    @n = @n.to_r
    @dp = Array.new(@n+1){Array.new(@n+1){Array.new(@n+1)}}
    @dp[0][0][0] = 0
  end

  private
  def dynamic(x,y,z)
    if x < 0 || y < 0 || z<0
      0
    else
      unless @dp[x][y][z]
        @dp[x][y][z] = (dynamic(x-1,y+1,z)*x + dynamic(x,y-1,z+1)*y + dynamic(x,y,z-1)*z + @n)/(x+y+z).to_r
      end
      @dp[x][y][z]
    end
  end

  public

  def ans
    g = (0...@n).group_by{|i| @a[i]}
    x = g[0] || []
    y = g[1] || []
    z = g[2] || []
    dynamic(x.size,y.size,z.size)
  end
end
### END: class TripleCardComp
iod = STDIN
n, = iod.gets.split.map &:to_i
a = iod.gets.split.map &:to_i
puts TripleCardComp.new(n,a).ans
exit 0

0