結果

問題 No.133 カードゲーム
ユーザー star_owl_mainstar_owl_main
提出日時 2019-09-19 17:49:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 1,197 bytes
コンパイル時間 813 ms
コンパイル使用メモリ 10,900 KB
実行使用メモリ 8,532 KB
最終ジャッジ日時 2023-09-26 16:32:42
合計ジャッジ時間 1,627 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,452 KB
testcase_01 AC 17 ms
8,532 KB
testcase_02 AC 18 ms
8,412 KB
testcase_03 AC 16 ms
8,416 KB
testcase_04 AC 16 ms
8,292 KB
testcase_05 AC 17 ms
8,500 KB
testcase_06 AC 17 ms
8,296 KB
testcase_07 AC 17 ms
8,360 KB
testcase_08 AC 16 ms
8,348 KB
testcase_09 AC 16 ms
8,384 KB
testcase_10 AC 18 ms
8,424 KB
testcase_11 AC 17 ms
8,352 KB
testcase_12 AC 17 ms
8,388 KB
testcase_13 AC 16 ms
8,256 KB
testcase_14 AC 16 ms
8,412 KB
testcase_15 AC 17 ms
8,408 KB
testcase_16 AC 18 ms
8,292 KB
testcase_17 AC 18 ms
8,452 KB
testcase_18 AC 17 ms
8,292 KB
testcase_19 AC 18 ms
8,332 KB
testcase_20 AC 18 ms
8,296 KB
testcase_21 AC 17 ms
8,360 KB
testcase_22 AC 17 ms
8,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import factorial
import sys
sys.setrecursionlimit(100000)

used1 = []
used2 = []
n = 0
ap = []
bp = []
a, b = ([], [])

def rec2(pos):
    ans = 0
    if pos == n:
        # a, b の勝ち数
        aa, bb = (0, 0)
        for x, y in zip(ap, bp):
            if a[x] > b[y]:
                aa += 1
            elif a[x] < b[y]:
                bb += 1
        return 1 if aa > bb else 0
    for i in range(n):
        if not used2[i]:
            bp.append(i)
            used2[i] = True
            ans += rec2(pos+1)
            used2[i] = False
            bp.pop()
    return ans


def rec1(pos):
    ans = 0
    if pos == n:
        # return rec2(0, a, b)
        return rec2(0)
    for i in range(n):
        if not used1[i]:
            used1[i] = True
            ap.append(i)
            ans += rec1(pos+1)
            ap.pop()
            used1[i] = False
    return ans


def main():
    global used1, used2, n, a, b
    n = int(input())
    used1 = [False for i in range(n)]
    used2 = [False for i in range(n)]
    a = [int(i) for i in input().split()]
    b = [int(i) for i in input().split()]
    print(rec1(0)/factorial(n)**2)


if __name__ == '__main__':
    main()
0