結果

問題 No.1151 チャレンジゲーム
ユーザー aru aruaru aru
提出日時 2020-10-24 20:50:15
言語 Go
(1.22.1)
結果
AC  
実行時間 278 ms / 2,000 ms
コード長 2,683 bytes
コンパイル時間 14,275 ms
コンパイル使用メモリ 210,428 KB
実行使用メモリ 21,440 KB
最終ジャッジ日時 2023-09-28 20:55:31
合計ジャッジ時間 24,216 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 70 ms
7,364 KB
testcase_14 AC 69 ms
7,372 KB
testcase_15 AC 70 ms
7,380 KB
testcase_16 AC 67 ms
7,364 KB
testcase_17 AC 69 ms
7,364 KB
testcase_18 AC 70 ms
7,372 KB
testcase_19 AC 67 ms
7,356 KB
testcase_20 AC 69 ms
7,352 KB
testcase_21 AC 71 ms
7,368 KB
testcase_22 AC 69 ms
7,368 KB
testcase_23 AC 69 ms
7,360 KB
testcase_24 AC 68 ms
7,352 KB
testcase_25 AC 69 ms
7,376 KB
testcase_26 AC 69 ms
7,364 KB
testcase_27 AC 69 ms
7,348 KB
testcase_28 AC 259 ms
21,428 KB
testcase_29 AC 269 ms
21,404 KB
testcase_30 AC 270 ms
21,412 KB
testcase_31 AC 261 ms
21,420 KB
testcase_32 AC 274 ms
21,404 KB
testcase_33 AC 272 ms
21,388 KB
testcase_34 AC 265 ms
21,416 KB
testcase_35 AC 269 ms
21,436 KB
testcase_36 AC 274 ms
21,428 KB
testcase_37 AC 270 ms
21,404 KB
testcase_38 AC 272 ms
21,404 KB
testcase_39 AC 271 ms
21,416 KB
testcase_40 AC 278 ms
21,440 KB
testcase_41 AC 270 ms
21,424 KB
testcase_42 AC 268 ms
21,420 KB
testcase_43 AC 271 ms
21,428 KB
testcase_44 AC 271 ms
21,432 KB
testcase_45 AC 262 ms
21,420 KB
testcase_46 AC 274 ms
21,408 KB
testcase_47 AC 271 ms
21,404 KB
testcase_48 AC 79 ms
12,088 KB
testcase_49 AC 272 ms
21,404 KB
testcase_50 AC 262 ms
21,428 KB
testcase_51 AC 271 ms
21,404 KB
testcase_52 AC 259 ms
21,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

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

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func getS() 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
}

var N int
var A []int

type TP [3]int

var mp = make(map[TP]float64)

func solve(c, state, win int) float64 {
	tmp := [3]int{c, state, win}
	v, ok := mp[tmp]
	if ok {
		return v
	}
	if state == 0 {
		s, t := 0, 0
		for i := 0; i < N; i++ {
			if win&(1<<i) != 0 {
				s += A[i]
			} else {
				t += A[i]
			}
		}
		if (c == 0 && s > t) || (c == 1 && s <= t) {
			mp[tmp] = 1
			return mp[tmp]
		} else {
			mp[tmp] = 0
			return mp[tmp]
		}
	}

	res := 0.0
	for a := 0; a < N; a++ {
		if state&(1<<a) == 0 {
			continue
		}
		if A[a] == 1 {
			nw := win
			if c == 0 {
				nw ^= 1 << a
				res = math.Max(res, (1 - solve(1-c, state^(1<<a), nw)))
				continue
			}
		}
		score := 1.0
		for b := 0; b < N; b++ {
			if state&(1<<b) == 0 {
				continue
			}
			coef := float64(A[a]*A[b]) / float64(A[a]+A[b]-1)
			val := 0.0
			if c == 0 {
				val += coef * (1 - solve(1-c, state^(1<<a), win^(1<<a))) / float64(A[a])
				val += coef * (solve(c, state^(1<<b), win)) * (float64(A[a]-1) / float64(A[a])) / float64(A[b])
			} else {
				val += coef * (1 - solve(1-c, state^(1<<a), win)) / float64(A[a])
				val += coef * (solve(c, state^(1<<b), win^(1<<b))) * (float64(A[a]-1) / float64(A[a])) / float64(A[b])
			}
			score = math.Min(score, val)
		}
		res = math.Max(res, score)
	}
	mp[tmp] = res
	return res
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	N = getI()
	A = getInts(N)

	ans := solve(0, (1<<N)-1, 0)
	out(ans)
}
0