結果

問題 No.108 トリプルカードコンプ
ユーザー sugarrrsugarrr
提出日時 2020-04-07 09:59:41
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 5,000 ms
コード長 2,051 bytes
コンパイル時間 1,769 ms
コンパイル使用メモリ 133,860 KB
実行使用メモリ 21,868 KB
最終ジャッジ日時 2023-08-20 14:37:56
合計ジャッジ時間 3,085 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
21,740 KB
testcase_01 AC 8 ms
21,868 KB
testcase_02 AC 9 ms
21,668 KB
testcase_03 AC 9 ms
21,800 KB
testcase_04 AC 9 ms
21,724 KB
testcase_05 AC 9 ms
21,748 KB
testcase_06 AC 9 ms
21,664 KB
testcase_07 AC 16 ms
21,756 KB
testcase_08 AC 9 ms
21,712 KB
testcase_09 AC 8 ms
21,732 KB
testcase_10 AC 9 ms
21,832 KB
testcase_11 AC 8 ms
21,728 KB
testcase_12 AC 8 ms
21,732 KB
testcase_13 AC 10 ms
21,752 KB
testcase_14 AC 9 ms
21,796 KB
testcase_15 AC 9 ms
21,748 KB
testcase_16 AC 9 ms
21,708 KB
testcase_17 AC 9 ms
21,692 KB
testcase_18 AC 14 ms
21,824 KB
testcase_19 AC 11 ms
21,804 KB
testcase_20 AC 11 ms
21,748 KB
testcase_21 AC 13 ms
21,736 KB
testcase_22 AC 9 ms
21,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////

ll n;
ll cnt[3];
#define N 105
dd dp[N][N][N];
dd dfs(ll i,ll j,ll k){
    if(dp[i][j][k]>=-0.5)return dp[i][j][k];
    if(i==0&&j==0&&k==0)return dp[i][j][k]=0;
    dp[i][j][k]=n;
    if(i>=1){
        dp[i][j][k]+=i*dfs(i-1,j+1,k);
    }
    if(j>=1){
        dp[i][j][k]+=j*dfs(i,j-1,k+1);
    }
    if(k>=1){
        dp[i][j][k]+=k*dfs(i,j,k-1);
    }
    dp[i][j][k]/=(i+j+k);
    return dp[i][j][k];
}

int main(){fastio
    cin>>n;
    rep(i,0,N-1)rep(j,0,N-1)rep(k,0,N-1)dp[i][j][k]=-1.0;
    rep(i,1,n){
        ll a;cin>>a;
        if(a<=2)cnt[a]++;
    }
    cout<<setprecision(20)<<dfs(cnt[0],cnt[1],cnt[2])<<endl;
    return 0;
}
0