結果

問題 No.58 イカサマなサイコロ
ユーザー tsuchinagatsuchinaga
提出日時 2019-03-18 16:03:35
言語 Go
(1.21.3)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 944 bytes
コンパイル時間 12,783 ms
コンパイル使用メモリ 213,852 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 13:32:58
合計ジャッジ時間 13,565 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import "fmt"

func main() {
	var n, m int
	_, _ = fmt.Scan(&n, &m)

	p1 := map[int]int{1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1}
	p1 = pattern58([]int{1, 2, 3, 4, 5, 6}, p1, n-1)

	p2 := map[int]int{}
	if n == m {
		p2 = map[int]int{4: 2, 5: 2, 6: 2}
		p2 = pattern58([]int{4, 5, 6, 4, 5, 6}, p2, m-1)
	} else {
		p2 = map[int]int{1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1}
		p2 = pattern58([]int{1, 2, 3, 4, 5, 6}, p2, n-1-m)
		p2 = pattern58([]int{4, 5, 6, 4, 5, 6}, p2, m)
	}

	// fmt.Println(p1, p2)

	var w, o int // 勝ち, それ以外
	for d1, c1 := range p1 {
		for d2, c2 := range p2 {
			if d1 < d2 {
				w += c1 * c2
			} else {
				o += c1 * c2
			}
		}
	}

	fmt.Printf("%f\n", float64(w)/float64(w+o))
}

func pattern58(p []int, q map[int]int, n int) map[int]int {
	if n == 0 {
		return q
	} else {
		r := map[int]int{}
		for k, v := range q {
			for _, n := range p {
				r[k+n] += v
			}
		}
		return pattern58(p, r, n-1)
	}
}
0