結果

問題 No.108 トリプルカードコンプ
ユーザー roarisroaris
提出日時 2019-11-09 01:42:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 779 bytes
コンパイル時間 1,515 ms
コンパイル使用メモリ 165,096 KB
実行使用メモリ 14,068 KB
最終ジャッジ日時 2023-10-13 06:33:24
合計ジャッジ時間 2,642 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
14,032 KB
testcase_01 AC 5 ms
13,844 KB
testcase_02 AC 5 ms
13,900 KB
testcase_03 AC 5 ms
14,024 KB
testcase_04 AC 5 ms
13,896 KB
testcase_05 AC 5 ms
14,008 KB
testcase_06 AC 4 ms
13,920 KB
testcase_07 AC 8 ms
14,068 KB
testcase_08 AC 6 ms
13,924 KB
testcase_09 AC 5 ms
13,892 KB
testcase_10 AC 5 ms
13,988 KB
testcase_11 AC 5 ms
13,900 KB
testcase_12 AC 5 ms
14,036 KB
testcase_13 AC 5 ms
14,016 KB
testcase_14 AC 5 ms
14,048 KB
testcase_15 AC 5 ms
13,904 KB
testcase_16 AC 5 ms
13,848 KB
testcase_17 AC 5 ms
13,844 KB
testcase_18 AC 7 ms
13,996 KB
testcase_19 AC 6 ms
13,896 KB
testcase_20 AC 5 ms
14,060 KB
testcase_21 AC 6 ms
14,036 KB
testcase_22 AC 5 ms
13,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long

int N;
double memo[110][110][110];

double rec(int i, int j, int k) {
    if (memo[i][j][k] >= 0) return memo[i][j][k];
     
    double res = 0;
    
    if (i > 0) res += i*rec(i-1, j+1, k);
    if (j > 0) res += j*rec(i, j-1, k+1);
    if (k > 0) res += k*rec(i, j, k-1);
    res += N;
    res /= i+j+k;
    
    return memo[i][j][k] = res;
}

signed main() {
    cin >> N;
    int zero=0, one=0, two=0;
    
    for (int i=0; i<N; i++) {
        int ai; cin >> ai;
        
        if (ai == 0) zero++;
        else if (ai == 1) one++;
        else if (ai == 2) two++;
    }
    
    memset(memo, -1, sizeof(memo));
    memo[0][0][0] = 0;
    
    cout << setprecision(10) << rec(zero, one, two) << endl;
}
0