結果

問題 No.108 トリプルカードコンプ
ユーザー hiro71687khiro71687k
提出日時 2023-01-16 21:11:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 5,000 ms
コード長 1,151 bytes
コンパイル時間 4,535 ms
コンパイル使用メモリ 269,244 KB
実行使用メモリ 20,184 KB
最終ジャッジ日時 2023-08-30 03:41:47
合計ジャッジ時間 5,787 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 25 ms
20,060 KB
testcase_08 AC 15 ms
19,980 KB
testcase_09 AC 15 ms
19,976 KB
testcase_10 AC 14 ms
20,008 KB
testcase_11 AC 15 ms
20,184 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 4 ms
5,048 KB
testcase_14 AC 3 ms
5,076 KB
testcase_15 AC 3 ms
4,936 KB
testcase_16 AC 4 ms
4,880 KB
testcase_17 AC 3 ms
4,408 KB
testcase_18 AC 21 ms
18,168 KB
testcase_19 AC 15 ms
17,332 KB
testcase_20 AC 15 ms
19,480 KB
testcase_21 AC 21 ms
19,624 KB
testcase_22 AC 14 ms
17,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll=long long;
using ld=long double;
ld pie=3.14159265359;
ll mod=998244353;
ll inf=99999999999999999;
vector<vector<vector<ld>>>dp;
ll n;
ll one=0,two=0,thr=0;
ld saiki(ll a,ll b,ll c){
    if (a+b+c>n||a<0||b<0)
    {
        return 0;
    }
    if (dp[a][b][c]!=-1)
    {
        return dp[a][b][c];
    }
    ld pl=(ld)n/(ld)(n-c);
    ld y=0;
    y+=(saiki(a+1,b,c)+pl)*((ld)(n-a-b-c)/(ld)(n-c));
    y+=(saiki(a-1,b+1,c)+pl)*((ld)(a)/(ld)(n-c));
    y+=(saiki(a,b-1,c+1)+pl)*((ld)(b)/(ld)(n-c));
    dp[a][b][c]=y;
    return dp[a][b][c];
}
int main(){
    cin >> n;
    vector<ll>a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    ll one=0,two=0,thr=0;
    for (ll i = 0; i < n; i++)
    {
        if (a[i]==1)
        {
            one+=1;
        }
        if (a[i]==2)
        {
            two+=1;
        }
        if (a[i]>=3)
        {
            thr+=1;
        }
    }
    dp.assign(n+1,vector<vector<ld>>(n+1,vector<ld>(n+1,-1)));
    dp[0][0][n]=0;
    cout << setprecision(20) << saiki(one,two,thr) << endl;
}
0