結果

問題 No.108 トリプルカードコンプ
ユーザー nightshrinenightshrine
提出日時 2021-02-26 15:04:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 4,369 bytes
コンパイル時間 4,561 ms
コンパイル使用メモリ 233,040 KB
実行使用メモリ 14,296 KB
最終ジャッジ日時 2024-04-10 06:41:08
合計ジャッジ時間 5,296 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
14,096 KB
testcase_01 AC 6 ms
14,252 KB
testcase_02 AC 6 ms
14,296 KB
testcase_03 AC 6 ms
14,112 KB
testcase_04 AC 5 ms
14,268 KB
testcase_05 AC 6 ms
14,112 KB
testcase_06 AC 5 ms
14,112 KB
testcase_07 AC 12 ms
14,208 KB
testcase_08 AC 6 ms
14,084 KB
testcase_09 AC 6 ms
14,108 KB
testcase_10 AC 6 ms
14,132 KB
testcase_11 AC 5 ms
14,228 KB
testcase_12 AC 6 ms
14,100 KB
testcase_13 AC 6 ms
14,220 KB
testcase_14 AC 6 ms
14,284 KB
testcase_15 AC 6 ms
14,172 KB
testcase_16 AC 6 ms
14,284 KB
testcase_17 AC 6 ms
14,260 KB
testcase_18 AC 10 ms
14,156 KB
testcase_19 AC 6 ms
14,124 KB
testcase_20 AC 6 ms
14,192 KB
testcase_21 AC 8 ms
14,080 KB
testcase_22 AC 5 ms
14,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define pf push_front
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vd> vvd;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll mod=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
const string tr="abcdefghijklmnopqrstuvwxyz";
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
ll llpow(ll n,ll i){if(i==0){return 1;}ll cnt=n;for(ll j=0;j<i-1;j++){n*=cnt;}return n;}
bool ip/*is_prime*/(long long N) {if (N == 1) return false;for (long long i = 2; i * i <= N; ++i) {if (N % i == 0) return false;}return true;}
int digit(ll N) {int ans = 0;while (N) {++ans;N /= 10;}return ans;}
vector<pair<ll,ll>> pf/*prime_factorize*/(ll n){vector<pair<ll,ll>> res;for(ll a=2;a*a<=n;a++){if(n%a!=0) continue;ll ex=0;while(n%a==0){ex++;n/=a;}res.pb({a,ex});}if(n!=1) res.pb({n,1});return res;}
vector<ll> div/*divisor*/(ll n){  vector<ll> res={1};for(ll a=2;a*a<=n;a++){if(n%a!=0) continue;ll b=n/a;res.pb(b);if(b!=a) res.pb(a);}sort(all(res));return res;}
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
struct UnionFind {
    vector<int> d;
    UnionFind(int n): d(n,-1) {}
    int root(int x) {
        if (d[x] < 0) return x;
        return d[x] = root(d[x]);
    }
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return root(x) == root(y);}
    int size(int x) { return -d[root(x)];}
};
mint f2(ll n) {if (n == 0) return 1;mint x = f2(n/2);x *= x;if (n%2 == 1) x *= 2;return x;}
mint choose(int n,int a){mint x=1,y=1;rep(i,a){x*=n-i;y*=i+1;}return x/y;}
ll xs/*xorsum nまでのxorの和*/(ll n){ll cnt=(n+1)/2;ll ans=cnt%2;if(n%2==0) ans^=n;return ans;}
ll Fa/*Factorial nの階乗*/(ll n){ll ans=1;rrep(i,n){ans*=i;}return ans;}

int n;
double dp[110][110][110];

double solve(int i,int j,int k){
    if(i==0&&j==0&&k==0) return 0.0;
    if(dp[i][j][k]>0) return dp[i][j][k];
    double res=0.0;
    if(i>0) res+=solve(i-1,j,k)*i;
    if(j>0) res+=solve(i+1,j-1,k)*j;
    if(k>0) res+=solve(i,j+1,k-1)*k;
    res+=n;
    res/=(i+j+k);
    return dp[i][j][k]=res;
}

int main(){
    cin>>n;
    int two=0,one=0,zero=0;
    rep(i,n) {
        int a;cin>>a;
        if(a==2) two++;
        if(a==1) one++;
        if(a==0) zero++;
    }
    memset(dp,-1,sizeof(dp));
    printf("%.10f\n",solve(two,one,zero));
    return 0;
}
0