結果

問題 No.108 トリプルカードコンプ
ユーザー salicinasalicina
提出日時 2021-03-08 14:43:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,210 bytes
コンパイル時間 925 ms
コンパイル使用メモリ 101,784 KB
実行使用メモリ 11,556 KB
最終ジャッジ日時 2023-07-31 07:45:27
合計ジャッジ時間 2,288 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 15 ms
11,556 KB
testcase_08 AC 9 ms
11,520 KB
testcase_09 AC 9 ms
11,460 KB
testcase_10 AC 9 ms
11,412 KB
testcase_11 AC 9 ms
11,412 KB
testcase_12 WA -
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 12 ms
10,832 KB
testcase_19 AC 9 ms
10,280 KB
testcase_20 AC 8 ms
11,196 KB
testcase_21 AC 12 ms
11,512 KB
testcase_22 AC 7 ms
10,548 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<<solve(solve,num[1],num[2],num[3])<<endl;
    
    // Fear misreading.
    return 0;
}
0