結果

問題 No.58 イカサマなサイコロ
ユーザー letrangerjpletrangerjp
提出日時 2017-06-17 18:19:38
言語 Ruby
(3.3.0)
結果
AC  
実行時間 103 ms / 5,000 ms
コード長 454 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 16,512 KB
最終ジャッジ日時 2024-04-08 20:30:46
合計ジャッジ時間 1,667 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
16,256 KB
testcase_01 AC 103 ms
16,512 KB
testcase_02 AC 92 ms
16,256 KB
testcase_03 AC 89 ms
16,256 KB
testcase_04 AC 95 ms
16,256 KB
testcase_05 AC 95 ms
16,384 KB
testcase_06 AC 100 ms
16,384 KB
testcase_07 AC 92 ms
16,256 KB
testcase_08 AC 94 ms
16,256 KB
testcase_09 AC 98 ms
16,384 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N,K=$<.map &:to_i

def f(n, k)
  dp = {}
  g = ->sum, i{
    dp[[sum,i]] ||= if i < 0 && sum == 0
      1
    elsif i < 0 || sum < 1
      0
    elsif i < k
      (4..6).map{|j| g[sum - j, i - 1].quo(3) }.sum
    else
      (1..6).map{|j| g[sum - j, i - 1].quo(6) }.sum
    end
  }
  (n..n*6).map{|sum| g[sum, n-1] }
end

taro = f(N, K)
jiro = f(N, 0)
ans = (1...taro.size).map{|i|
  (0...i).map{|j|
    taro[i] * jiro[j]
  }.sum
}.sum
puts "%.3f" % ans
0