結果

問題 No.108 トリプルカードコンプ
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2018-03-19 10:27:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 2,176 bytes
コンパイル時間 1,450 ms
コンパイル使用メモリ 164,412 KB
実行使用メモリ 12,468 KB
最終ジャッジ日時 2023-08-30 03:33:59
合計ジャッジ時間 2,768 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,808 KB
testcase_01 AC 2 ms
5,564 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
5,568 KB
testcase_04 AC 2 ms
5,792 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 10 ms
12,468 KB
testcase_08 AC 2 ms
7,656 KB
testcase_09 AC 2 ms
5,692 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
7,624 KB
testcase_13 AC 3 ms
10,216 KB
testcase_14 AC 3 ms
7,784 KB
testcase_15 AC 3 ms
7,860 KB
testcase_16 AC 3 ms
7,796 KB
testcase_17 AC 2 ms
7,852 KB
testcase_18 AC 8 ms
11,264 KB
testcase_19 AC 4 ms
8,248 KB
testcase_20 AC 3 ms
7,752 KB
testcase_21 AC 6 ms
10,480 KB
testcase_22 AC 2 ms
7,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/






int N;
double dp[101][101][101];
int vis[101][101][101];
//---------------------------------------------------------------------------------------------------
double f(int c0, int c1, int c2) {
    if (vis[c0][c1][c2]) return dp[c0][c1][c2];
    
    int n = c0 + c1 + c2;
    if (!n) return 0;
    double ex = (double)N / (double)n;

    double res = 0;
    if (c0) res += (f(c0 - 1, c1 + 1, c2) + ex) * c0 / n;
    if (c1) res += (f(c0, c1 - 1, c2 + 1) + ex) * c1 / n;
    if (c2) res += (f(c0, c1, c2 - 1) + ex) * c2 / n;

    vis[c0][c1][c2] = 1;
    return dp[c0][c1][c2] = res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;

    int c0 = 0, c1 = 0, c2 = 0;
    rep(i, 0, N) {
        int a; cin >> a;
        if (a == 0) c0++;
        else if (a == 1) c1++;
        else if (a == 2) c2++;
    }

    double ans = f(c0, c1, c2);
    printf("%.10f\n", ans);
}
0