結果

問題 No.133 カードゲーム
ユーザー tnoda_tnoda_
提出日時 2015-01-23 02:04:36
言語 Go
(1.22.1)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 809 bytes
コンパイル時間 13,414 ms
コンパイル使用メモリ 215,732 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-07 09:10:03
合計ジャッジ時間 12,843 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package main

import (
	"fmt"
	"sort"
)

var as, bs []int
var awin int

func dfs(pa, pb int) {
	n := len(as)

	if n == 0 {
		if pa > pb {
			awin++
		}
		return
	}

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			sort.Ints(as)
			sort.Ints(bs)
			a, b := as[i], bs[j]
			as[i], as = as[n-1], as[:n-1]
			bs[j], bs = bs[n-1], bs[:n-1]
			sort.Ints(as)
			sort.Ints(bs)
			if a > b {
				dfs(pa+1, pb)
			} else {
				dfs(pa, pb+1)
			}
			as = append(as, a)
			bs = append(bs, b)
		}
	}
}

func p(n int) int {
	if n == 0 {
		return 1
	}
	return n * p(n-1)
}

func main() {
	var n int
	fmt.Scan(&n)
	as, bs = make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&as[i])
	}
	for i := 0; i < n; i++ {
		fmt.Scan(&bs[i])
	}
	dfs(0, 0)
	fmt.Printf("%f\n", float64(awin)/float64(p(n)*p(n)))
}
0