結果

問題 No.108 トリプルカードコンプ
ユーザー 👑 colognecologne
提出日時 2022-02-02 17:01:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 183 ms / 5,000 ms
コード長 761 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 82,728 KB
最終ジャッジ日時 2023-09-02 02:51:41
合計ジャッジ時間 3,870 ms
ジャッジサーバーID
(参考情報)
judge16 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,328 KB
testcase_01 AC 71 ms
71,352 KB
testcase_02 AC 75 ms
71,312 KB
testcase_03 AC 73 ms
71,396 KB
testcase_04 AC 74 ms
71,452 KB
testcase_05 AC 74 ms
71,296 KB
testcase_06 AC 74 ms
71,408 KB
testcase_07 AC 183 ms
82,728 KB
testcase_08 AC 88 ms
76,068 KB
testcase_09 AC 74 ms
71,372 KB
testcase_10 AC 72 ms
71,124 KB
testcase_11 AC 73 ms
71,416 KB
testcase_12 AC 73 ms
71,260 KB
testcase_13 AC 101 ms
77,384 KB
testcase_14 AC 96 ms
77,200 KB
testcase_15 AC 86 ms
75,992 KB
testcase_16 AC 99 ms
77,440 KB
testcase_17 AC 77 ms
75,100 KB
testcase_18 AC 159 ms
80,988 KB
testcase_19 AC 116 ms
78,152 KB
testcase_20 AC 104 ms
77,532 KB
testcase_21 AC 140 ms
79,908 KB
testcase_22 AC 94 ms
76,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys


def input(): return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    *A, = map(int, input().split())
    c0, c1, c2 = A.count(0), A.count(1), A.count(2)

    DP = [[[None]*(c0+c1+c2-(i+j)+1) for j in range(c1+c0-i+1)]
          for i in range(c0+1)]

    def solve(a, b, c):
        if a == b == c == 0:
            return 0

        if DP[a][b][c] is not None:
            return DP[a][b][c]

        ans = 0
        if a > 0:
            ans += a * solve(a-1, b+1, c)
        if b > 0:
            ans += b * solve(a, b-1, c+1)
        if c > 0:
            ans += c * solve(a, b, c-1)

        DP[a][b][c] = (ans + N) / (a+b+c)
        return DP[a][b][c]

    print(solve(c0, c1, c2))


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