結果

問題 No.108 トリプルカードコンプ
ユーザー horitaka1999horitaka1999
提出日時 2021-11-04 23:17:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 211 ms / 5,000 ms
コード長 1,202 bytes
コンパイル時間 444 ms
コンパイル使用メモリ 87,312 KB
実行使用メモリ 101,332 KB
最終ジャッジ日時 2023-08-05 08:18:30
合計ジャッジ時間 5,038 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
76,296 KB
testcase_01 AC 81 ms
76,216 KB
testcase_02 AC 86 ms
76,340 KB
testcase_03 AC 81 ms
76,040 KB
testcase_04 AC 82 ms
76,100 KB
testcase_05 AC 80 ms
75,956 KB
testcase_06 AC 81 ms
76,328 KB
testcase_07 AC 211 ms
101,332 KB
testcase_08 AC 131 ms
95,684 KB
testcase_09 AC 104 ms
84,416 KB
testcase_10 AC 104 ms
84,288 KB
testcase_11 AC 101 ms
84,180 KB
testcase_12 AC 81 ms
75,940 KB
testcase_13 AC 120 ms
82,028 KB
testcase_14 AC 110 ms
81,752 KB
testcase_15 AC 105 ms
81,520 KB
testcase_16 AC 116 ms
81,960 KB
testcase_17 AC 97 ms
80,964 KB
testcase_18 AC 171 ms
97,008 KB
testcase_19 AC 144 ms
94,556 KB
testcase_20 AC 140 ms
95,780 KB
testcase_21 AC 161 ms
97,840 KB
testcase_22 AC 135 ms
94,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**7)
N = int(input())        
A = list(map(int,input().split()))
dp = [[[0 for _ in range(N+1)] for _ in range(N+1)] for _ in range(N+1)]
memo = [[[False for _ in range(N+1)] for _ in range(101)] for _ in range(101)]
memo[N][N][N] = True
def DP(x,y,z):
    if x == N and y == N and z == N:
        return 
    if x >= y >= z:
        pass
    else:
        return
    if x + 1 <= N:
        if memo[x+1][y][z]:
            dp[x][y][z] += (N-x) * (dp[x+1][y][z])
        else:
            DP(x+1,y,z)
            dp[x][y][z] += (N-x) * (dp[x+1][y][z]) 
    if y + 1 <= N:
        if memo[x][y+1][z]: 
            dp[x][y][z] += (x-y) * (dp[x][y+1][z]) 
        else:
            DP(x,y+1,z)
            dp[x][y][z] += (x-y) * (dp[x][y+1][z]) 
    if z + 1 <= N:
        if memo[x][y][z+1]:
            dp[x][y][z] += (y-z) * (dp[x][y][z+1]) 
        else:
            DP(x,y,z+1)
            dp[x][y][z] += (y-z) * (dp[x][y][z+1]) 
    dp[x][y][z] += N
    dp[x][y][z] /=  N -z
    memo[x][y][z] = True
x = 0
y = 0
z = 0
for i in range(N):
    if A[i] >= 1:
        x += 1
    if A[i] >= 2:
        y += 1
    if A[i] >= 3:
        z += 1
DP(x,y,z)
print(dp[x][y][z])
0