結果
| 問題 |
No.58 イカサマなサイコロ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-08-14 02:32:44 |
| 言語 | Nim (2.2.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 906 bytes |
| コンパイル時間 | 3,353 ms |
| コンパイル使用メモリ | 68,992 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-30 02:32:52 |
| 合計ジャッジ時間 | 3,829 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 50) Warning: Use the new 'sugar' module instead; future is deprecated [Deprecated] /home/judge/data/code/Main.nim(1, 57) Warning: imported and not used: 'macros' [UnusedImport] /home/judge/data/code/Main.nim(1, 50) Warning: imported and not used: 'future' [UnusedImport] /home/judge/data/code/Main.nim(1, 26) Warning: imported and not used: 'strscans' [UnusedImport] /home/judge/data/code/Main.nim(1, 35) Warning: imported and not used: 'algorithm' [UnusedImport] /home/judge/data/code/Main.nim(1, 45) Warning: imported and not used: 'math' [UnusedImport]
ソースコード
import sequtils,strutils,strscans,algorithm,math,future,macros
template get*():string = stdin.readLine() #.strip()
template times*(n:int,body:untyped): untyped = (for _ in 0..<n: body)
proc probAdd(ps,qs:seq[float]):seq[float] =
result = newSeqWith(ps.len + qs.len - 1,0.0)
for i,p in ps:
for j,q in qs:
result[i + j] += p * q
proc prob(base:seq[float],n:int): seq[float] =
result = @[1.0]
n.times: result = probAdd(result,base)
# K:445566 N-K:123456 => P(Win) | sum: 大きい方が勝ち / 同じなら引き分け
let
N = get().parseInt() # < 10
K = get().parseInt()
let
ps = toSeq(0..6).mapIt(if it >= 1 : 1.0/6.0 else: 0.0).prob(N)
qs1 = toSeq(0..6).mapIt(if it >= 4 : 1.0/3.0 else: 0.0).prob(K)
qs2 = toSeq(0..6).mapIt(if it >= 1 : 1.0/6.0 else: 0.0).prob(N-K)
qs = qs1.probAdd(qs2)
var ans = 0.0
for i,p in ps:
for j,q in qs:
if j > i : ans += p * q
echo ans