結果

問題 No.108 トリプルカードコンプ
ユーザー 👑 rin204rin204
提出日時 2022-07-09 16:41:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 232 ms / 5,000 ms
コード長 663 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 86,936 KB
実行使用メモリ 103,304 KB
最終ジャッジ日時 2023-08-30 00:17:10
合計ジャッジ時間 4,398 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,104 KB
testcase_01 AC 74 ms
71,412 KB
testcase_02 AC 72 ms
71,312 KB
testcase_03 AC 78 ms
71,396 KB
testcase_04 AC 73 ms
71,404 KB
testcase_05 AC 74 ms
71,272 KB
testcase_06 AC 72 ms
71,144 KB
testcase_07 AC 232 ms
103,304 KB
testcase_08 AC 85 ms
76,232 KB
testcase_09 AC 70 ms
71,428 KB
testcase_10 AC 73 ms
71,464 KB
testcase_11 AC 74 ms
71,380 KB
testcase_12 AC 73 ms
71,520 KB
testcase_13 AC 96 ms
78,488 KB
testcase_14 AC 93 ms
77,660 KB
testcase_15 AC 89 ms
76,456 KB
testcase_16 AC 96 ms
77,700 KB
testcase_17 AC 79 ms
75,460 KB
testcase_18 AC 163 ms
92,396 KB
testcase_19 AC 114 ms
80,496 KB
testcase_20 AC 99 ms
79,084 KB
testcase_21 AC 138 ms
86,564 KB
testcase_22 AC 89 ms
76,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = list(map(int, input().split()))
zero = 0
one = 0
two = 0
for a in A:
    if a == 0:
        zero += 1
    elif a == 1:
        one += 1
    elif a == 2:
        two += 1
    else:
        pass

tot = zero + one + two + 1
memo = {}
def dfs(z, o, t):
    if z + o + t == 0:
        return 0
    tmp = (z * tot + o) * tot + t
    if tmp in memo:
        return memo[tmp]
    ret = 1
    if z >= 1:
        ret += dfs(z - 1, o + 1, t) * z / n
    if o >= 1:
        ret += dfs(z, o - 1, t + 1) * o / n
    if t >= 1:
        ret += dfs(z, o, t - 1) * t / n
    ret *= n / (z + o + t)
    memo[tmp] = ret
    return ret

print(dfs(zero, one, two))
0