結果

問題 No.133 カードゲーム
ユーザー yukirinyukirin
提出日時 2016-03-01 20:05:47
言語 Go
(1.22.1)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,445 bytes
コンパイル時間 14,651 ms
コンパイル使用メモリ 201,832 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-07 09:25:13
合計ジャッジ時間 10,087 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,384 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a, b := make([]int, n), make([]int, n)
	for i := range a {
		a[i] = nextInt()
	}
	for i := range b {
		b[i] = nextInt()
	}

	win, all := 0, 0

	f := func(a []int) {
		c := 0
		for i, v := range a {
			if v > b[i] {
				c++
				continue
			}

			if b[i] > v {
				c--
				continue
			}
		}
		if c > 0 {
			win++
		}
		all++
	}

	perm(a, n, f)
	fmt.Println(float64(win) / float64(all))
}

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

func nextInt() int {
	i, _ := strconv.Atoi(nextLine())
	return i
}

func comb(a []int, r int, fn func([]int)) {
	if r > len(a) || r < 1 {
		return
	}

	var f func([]int, int, int)
	f = func(ret []int, last, c int) {
		if c == 0 {
			fn(ret)
			return
		}

		c--
		for i, v := range a[last : len(a)-c] {
			ret[r-c-1] = v
			f(ret, i+last+1, c)
		}
	}

	ret := make([]int, r)
	f(ret, 0, r)
}

func perm(a []int, r int, fn func([]int)) {
	permL := make([]int, r)
	f := func(s []int) {
		copy(permL, s)

		k, i := 1, 0
		c := make([]int, r+1)
		for i := 1; i < len(c); i++ {
			c[i] = i
		}

		for k < r {
			if k&1 == 1 {
				i = c[k]
			} else {
				i = 0
			}

			permL[k], permL[i] = permL[i], permL[k]

			fn(permL)
			k = 1
			for ; c[k] == 0; k++ {
				c[k] = k
			}
			c[k]--
		}
	}

	if r < 2 {
		comb(a, r, fn)
		return
	}
	comb(a, r, f)
}
0