結果

問題 No.162 8020運動
ユーザー aru aruaru aru
提出日時 2020-08-28 21:44:49
言語 Go
(1.22.1)
結果
AC  
実行時間 1,069 ms / 5,000 ms
コード長 2,048 bytes
コンパイル時間 12,291 ms
コンパイル使用メモリ 231,992 KB
実行使用メモリ 124,832 KB
最終ジャッジ日時 2024-04-26 12:44:19
合計ジャッジ時間 42,018 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 803 ms
119,328 KB
testcase_01 AC 924 ms
119,680 KB
testcase_02 AC 992 ms
121,492 KB
testcase_03 AC 1,069 ms
121,992 KB
testcase_04 AC 1,058 ms
121,088 KB
testcase_05 AC 1,057 ms
122,132 KB
testcase_06 AC 1,055 ms
122,144 KB
testcase_07 AC 1,051 ms
121,108 KB
testcase_08 AC 1,054 ms
120,704 KB
testcase_09 AC 804 ms
119,168 KB
testcase_10 AC 993 ms
123,288 KB
testcase_11 AC 927 ms
122,252 KB
testcase_12 AC 858 ms
120,864 KB
testcase_13 AC 1,060 ms
124,076 KB
testcase_14 AC 820 ms
118,528 KB
testcase_15 AC 813 ms
119,068 KB
testcase_16 AC 874 ms
118,912 KB
testcase_17 AC 834 ms
120,468 KB
testcase_18 AC 1,041 ms
121,984 KB
testcase_19 AC 972 ms
120,836 KB
testcase_20 AC 1,002 ms
124,832 KB
testcase_21 AC 1,001 ms
122,752 KB
testcase_22 AC 988 ms
123,392 KB
testcase_23 AC 1,001 ms
123,924 KB
testcase_24 AC 1,041 ms
120,340 KB
testcase_25 AC 1,018 ms
124,160 KB
testcase_26 AC 800 ms
118,528 KB
testcase_27 AC 937 ms
123,152 KB
testcase_28 AC 1,039 ms
120,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"math/bits"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

type pair struct {
	n int
	p float64
}

var P [3]float64
var ns [][]pair

func prob(prev, next int) float64 {
	res := 1.0
	for i := 0; i < 14; i++ {
		if ((prev >> i) & 1) == 0 {
			continue
		}
		var p float64
		if i == 0 {
			p = P[(prev>>1)&1]
		} else if i == 13 {
			p = P[(prev>>12)&1]
		} else {
			p = P[(prev>>(i-1)&1)+(prev>>(i+1))&1]
		}

		if next>>i&1 == 1 {
			res *= 1 - p
		} else {
			res *= p
		}
	}
	return res
}

var dp [21][1 << 14]float64

func main() {
	sc.Split(bufio.ScanWords)
	N := 80 - getInt()
	p := getInts(3)
	for i := 0; i < 3; i++ {
		P[i] = float64(p[i]) / 100.0
	}

	ns = make([][]pair, 1<<14)
	for i := 0; i < 1<<14; i++ {
		for j := 0; j < 1<<14; j++ {
			if i&j != j {
				continue
			}
			ns[i] = append(ns[i], pair{j, prob(i, j)})
		}
	}

	dp[0][(1<<14)-1] = 1.0
	for i := 0; i < N; i++ {
		for j := 0; j < 1<<14; j++ {
			for _, p := range ns[j] {
				dp[i+1][p.n] += dp[i][j] * p.p
			}
		}
	}

	res := 0.0
	for i := 0; i < 1<<14; i++ {
		res += dp[N][i] * float64(bits.OnesCount(uint(i)))
	}
	out(res * 2)
}
0