結果

問題 No.108 トリプルカードコンプ
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2022-12-23 04:41:37
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 5,000 ms
コード長 959 bytes
コンパイル時間 1,047 ms
コンパイル使用メモリ 142,828 KB
実行使用メモリ 19,840 KB
最終ジャッジ日時 2024-04-29 04:10:37
合計ジャッジ時間 2,289 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
19,712 KB
testcase_01 AC 14 ms
19,584 KB
testcase_02 AC 14 ms
19,712 KB
testcase_03 AC 14 ms
19,712 KB
testcase_04 AC 14 ms
19,712 KB
testcase_05 AC 14 ms
19,584 KB
testcase_06 AC 15 ms
19,840 KB
testcase_07 AC 22 ms
19,712 KB
testcase_08 AC 15 ms
19,712 KB
testcase_09 AC 14 ms
19,840 KB
testcase_10 AC 14 ms
19,712 KB
testcase_11 AC 14 ms
19,584 KB
testcase_12 AC 14 ms
19,584 KB
testcase_13 AC 14 ms
19,712 KB
testcase_14 AC 14 ms
19,712 KB
testcase_15 AC 15 ms
19,584 KB
testcase_16 AC 14 ms
19,840 KB
testcase_17 AC 14 ms
19,840 KB
testcase_18 AC 19 ms
19,712 KB
testcase_19 AC 16 ms
19,840 KB
testcase_20 AC 15 ms
19,712 KB
testcase_21 AC 18 ms
19,712 KB
testcase_22 AC 14 ms
19,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>

using namespace std;

int N;
long double ans[101][101][101];

long double f(int a, int b, int c){
    if (a < 0 || b < 0 || c < 0) return 0;
    if (a == 0 && b == 0 && c == 0) return 0;
    if (ans[a][b][c] != -1) return ans[a][b][c];
    long double res;
    res = f(a-1, b, c) * a + f(a+1, b-1, c) * b + f(a, b+1, c-1) * c + (long double) N;
    res /= (long double) (a+b+c);
    return ans[a][b][c] = res;
}

int main(){

    for (int i=0; i<=100; i++) for (int j=0; j<=100; j++) for (int k=0; k<=100; k++) ans[i][j][k] = -1;

    int a=0, b=0, c=0, d;
    cin >> N;

    for (int i=0; i<N; i++){
        cin >> d;
        if (d == 0) c++;
        else if (d == 1) b++;
        else if (d == 2) a++;
    }

    cout << setprecision(18) << f(a, b, c) << endl;

    return 0;
}
0