結果

問題 No.108 トリプルカードコンプ
ユーザー salicinasalicina
提出日時 2021-03-08 14:47:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 5,000 ms
コード長 1,235 bytes
コンパイル時間 1,117 ms
コンパイル使用メモリ 101,508 KB
実行使用メモリ 11,728 KB
最終ジャッジ日時 2023-07-31 07:50:20
合計ジャッジ時間 2,221 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 15 ms
11,544 KB
testcase_08 AC 8 ms
11,548 KB
testcase_09 AC 8 ms
11,552 KB
testcase_10 AC 8 ms
11,488 KB
testcase_11 AC 8 ms
11,608 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 2 ms
4,388 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 12 ms
11,024 KB
testcase_19 AC 8 ms
10,500 KB
testcase_20 AC 8 ms
11,596 KB
testcase_21 AC 11 ms
11,728 KB
testcase_22 AC 7 ms
10,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip> //<<setprecision(12), or <<fixed
#include <algorithm>
#include <functional>
#include <map>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
 
using namespace std;

using ll=long long;
using ull=unsigned long long;
using pll=pair<ll,ll>;

int main()
{
    ll N;
    cin>>N;
    vector<ll> A(N);
    for(auto& a:A) cin>>a;
    
    vector<ll> num(4,0);
    for(auto& a:A)
    {
        num[max(0LL,3-a)]++;
    }
    
    //1,2,3
    vector<vector<vector<double>>> dp(N+1,vector<vector<double>>(N+1,vector<double>(N+1,-1)));
    dp[0][0][0]=0;
    
    auto solve=[&](auto& solve, ll a, ll b, ll c)
    {
        if(dp[a][b][c]!=-1) return dp[a][b][c];
        
        double res=0;
        if(a!=0) res+=(solve(solve,a-1,b,c)+1)*a/(double)(a+b+c);
        if(b!=0) res+=(solve(solve,a+1,b-1,c)+1)*b/(double)(a+b+c);
        if(c!=0) res+=(solve(solve,a,b+1,c-1)+1)*c/(double)(a+b+c);
        res+=(N/(double)(a+b+c)-1);
                    
        dp[a][b][c]=res;
        //cout<<a<<" "<<b<<" "<<c<<" "<<res<<endl;
        return dp[a][b][c];
    };
    
    cout<<fixed<<setprecision(15)<<solve(solve,num[1],num[2],num[3])<<endl;
    
    // Fear misreading.
    return 0;
}
0