結果

問題 No.58 イカサマなサイコロ
ユーザー tshigtshig
提出日時 2016-08-18 16:10:20
言語 Ruby
(3.3.0)
結果
AC  
実行時間 86 ms / 5,000 ms
コード長 767 bytes
コンパイル時間 37 ms
コンパイル使用メモリ 11,528 KB
実行使用メモリ 15,340 KB
最終ジャッジ日時 2023-08-27 06:35:04
合計ジャッジ時間 1,638 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
14,948 KB
testcase_01 AC 86 ms
15,176 KB
testcase_02 AC 83 ms
15,228 KB
testcase_03 AC 85 ms
15,176 KB
testcase_04 AC 84 ms
15,052 KB
testcase_05 AC 83 ms
15,320 KB
testcase_06 AC 83 ms
15,340 KB
testcase_07 AC 84 ms
15,224 KB
testcase_08 AC 83 ms
15,052 KB
testcase_09 AC 84 ms
15,232 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Calc0058
  EPS = 1e-3

  def initialize(args)
    args = args.map { |l| l.chomp.split(/\s+/) }
    @n = args.shift.first.to_i
    @k = args.shift.first.to_i
  end

  def run
    sais_taro = Array.new(@n - @k) { (1..6).to_a } + Array.new(@k) { [4, 5, 6] * 2 }
    sais_jiro = Array.new(@n) { (1..6).to_a }

    hist_taro = make_hist(sais_taro, [1])
    hist_jiro = make_hist(sais_jiro, [1])

    hist_jiro.map.with_index { |h, i|
      h * (hist_taro.drop(i + 1).inject(:+) || 0)
    }.inject(:+).to_f / 6 ** (@n * 2)
  end

  def make_hist(sais, hist)
    sais.each do |sai|
      hist = sai.map { |d| [0] * d + hist + [0] * (sai.max - d) }.transpose.map { |r| r.inject(:+) }
    end
    hist
  end
end

puts Calc0058.new(STDIN.readlines).run if __FILE__ == $0
0