結果

問題 No.108 トリプルカードコンプ
ユーザー kimiyukikimiyuki
提出日時 2016-10-06 05:51:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 1,452 bytes
コンパイル時間 753 ms
コンパイル使用メモリ 56,024 KB
実行使用メモリ 11,036 KB
最終ジャッジ日時 2023-08-13 23:47:56
合計ジャッジ時間 1,892 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 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 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 10 ms
11,036 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 6 ms
7,232 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <array>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
using namespace std;
template <typename T, typename X> auto vectors(T a, X x) { return vector<T>(x, a); }
template <typename T, typename X, typename Y, typename... Zs> auto vectors(T a, X x, Y y, Zs... zs) { auto cont = vectors(a, y, zs...); return vector<decltype(cont)>(x, cont); }
int main() {
    int n; scanf("%d", &n);
    vector<int> a(n); repeat (i,n) scanf("%d", &a[i]);
    array<int,3> cnt = {}; repeat (i,n) if (a[i] < 3) cnt[a[i]] += 1;
    array<int,3> l; repeat (i,3) l[i] = (i ? l[i-1] : 0) + cnt[i];
    vector<vector<vector<double> > > dp = vectors(double(), l[0]+1, l[1]+1, l[2]+1);
    repeat (i,l[0]+1) {
        repeat (j,l[1]+1-i) {
            repeat (k,l[2]+1-i-j) {
                if (i == 0 and j == 0 and k == 0) continue;
                double p = (i + j + k) /(double) n;
                double qi = i /(double) (i + j + k);
                double qj = j /(double) (i + j + k);
                double qk = k /(double) (i + j + k);
                dp[i][j][k] = 1/p;
                if (i-1 >= 0 and j+1 < l[1]+1) dp[i][j][k] += qi * dp[i-1][j+1][k];
                if (j-1 >= 0 and k+1 < l[2]+1) dp[i][j][k] += qj * dp[i][j-1][k+1];
                if (k-1 >= 0                 ) dp[i][j][k] += qk * dp[i][j][k-1];
            }
        }
    }
    printf("%.12f\n", dp[cnt[0]][cnt[1]][cnt[2]]);
    return 0;
}
0