結果

問題 No.58 イカサマなサイコロ
ユーザー 👑 horiesinitihoriesiniti
提出日時 2018-03-14 17:56:32
言語 Ruby
(3.3.0)
結果
AC  
実行時間 85 ms / 5,000 ms
コード長 528 bytes
コンパイル時間 52 ms
コンパイル使用メモリ 11,548 KB
実行使用メモリ 15,332 KB
最終ジャッジ日時 2023-08-18 19:59:42
合計ジャッジ時間 1,500 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
15,080 KB
testcase_01 AC 72 ms
15,300 KB
testcase_02 AC 71 ms
15,288 KB
testcase_03 AC 69 ms
15,240 KB
testcase_04 AC 70 ms
15,132 KB
testcase_05 AC 72 ms
15,244 KB
testcase_06 AC 69 ms
15,160 KB
testcase_07 AC 70 ms
15,332 KB
testcase_08 AC 68 ms
15,140 KB
testcase_09 AC 72 ms
15,304 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def f(dp,s)
	dp2=61.times.map{0.0}
	dp.size.times{|i|
		if dp[i]>0
			s.each{|e|
				dp2[i+e]+=dp[i]
			}
		end
	}
	return dp2
end

dp1=61.times.map{0.0}
dp2=61.times.map{0.0}
dp1[0]=1.0
dp2[0]=1.0

n=gets.to_i
m=gets.to_i
n.times{
	dp1=f(dp1,[1,2,3,4,5,6])
}
m.times{
	dp2=f(dp2,[4,5,6,4,5,6])
}
(n-m).times{
	dp2=f(dp2,[1,2,3,4,5,6])
}
sum1=dp1.inject(0){|sum,e|
	sum+e
}
sum2=dp2.inject(0){|sum,e|
	sum+e
}
ans=0.0
dp1.each{|e|
	r1=e/sum1
	dp2.shift
	sum3=dp2.inject(0){|sum,e|
		sum+e
	}
	r2=sum3/sum2
	ans+=r1*r2
}
puts ans
0