結果

問題 No.162 8020運動
ユーザー hama_duhama_du
提出日時 2015-11-24 23:01:18
言語 Go
(1.22.1)
結果
AC  
実行時間 1,150 ms / 5,000 ms
コード長 1,152 bytes
コンパイル時間 11,755 ms
コンパイル使用メモリ 236,912 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 03:37:59
合計ジャッジ時間 25,222 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 4 ms
5,248 KB
testcase_02 AC 813 ms
5,248 KB
testcase_03 AC 662 ms
5,376 KB
testcase_04 AC 1,150 ms
5,376 KB
testcase_05 AC 1,111 ms
5,376 KB
testcase_06 AC 1,121 ms
5,376 KB
testcase_07 AC 1,136 ms
5,376 KB
testcase_08 AC 1,127 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 164 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 780 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 871 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 891 ms
5,376 KB
testcase_24 AC 830 ms
5,376 KB
testcase_25 AC 951 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 621 ms
5,376 KB
testcase_28 AC 594 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main
import (
	"fmt"
)

var age int
var P [3]int
var dp [][]float64

func main() {
	fmt.Scan(&age, &P[0], &P[1], &P[2])
	age = 80 - age

	dp = make([][]float64, 2)
	dp[0] = make([]float64, 1<<14)
	dp[1] = make([]float64, 1<<14)
	dp[0][0] = 1.0

	for i := 0 ; i < age ; i++ {
		fi := i % 2
		ti := 1 - fi
		for p := 0 ; p < (1<<14) ; p++ {
			dp[ti][p] = 0.0
		}
		for p := 0 ; p < (1<<14) ; p++ {
			if dp[fi][p] == 0 {
				continue
			}
			dfs(ti, dp[fi][p], uint(p), 0, 0)
		}
	}

	exp := 0.0
	for p := 0 ; p < (1<<14) ; p++ {
		cnt := 0
		for i := uint(0) ; i < 14 ; i++ {
			if p & (1<<i) == 0 {
				cnt++
			}
		}
		exp += float64(cnt) * dp[age%2][p]
	}
	exp *= 2

	fmt.Printf("%.9f\n", exp)
}

func dfs(ti int, rate float64, ptn, tptn, idx uint) {
	if idx == 14 {
		dp[ti][tptn] += rate
		return
	}
	if ptn & (1<<idx) >= 1 {
		dfs(ti, rate, ptn, tptn | (1<<idx), idx+1)
	}  else {
		pw := 0
		if idx >= 1 && ptn & (1<<(idx-1)) == 0 {
			pw++
		}
		if idx <= 12 && ptn & (1<<(idx+1)) == 0 {
			pw++
		}
		dfs(ti, rate * float64(P[pw]) / 100, ptn, tptn | (1<<idx), idx+1)
		dfs(ti, rate * float64(100 - P[pw]) / 100, ptn, tptn, idx+1)
	}
}
0