結果

問題 No.108 トリプルカードコンプ
ユーザー uenokuuenoku
提出日時 2020-04-28 20:52:14
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,615 bytes
コンパイル時間 1,484 ms
コンパイル使用メモリ 167,644 KB
実行使用メモリ 12,296 KB
最終ジャッジ日時 2023-08-16 17:54:31
合計ジャッジ時間 2,541 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 8 ms
12,184 KB
testcase_08 AC 4 ms
12,284 KB
testcase_09 AC 4 ms
12,296 KB
testcase_10 AC 4 ms
12,140 KB
testcase_11 AC 4 ms
12,292 KB
testcase_12 WA -
testcase_13 AC 3 ms
6,588 KB
testcase_14 AC 2 ms
6,704 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2 ms
6,528 KB
testcase_18 AC 6 ms
11,728 KB
testcase_19 AC 4 ms
11,612 KB
testcase_20 AC 4 ms
12,176 KB
testcase_21 AC 5 ms
12,212 KB
testcase_22 AC 4 ms
11,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;

using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);
double dp[105][105][105] = {};
int n;
double calc(int zero, int one, int two)
{
    double &ret = dp[zero][one][two];
    if (ret > 0)
        return ret;
    if (zero == 0 && one == 0 && two == 0)
        return 0;
    ret = 1;
    double p0 = double(zero) / double(n);
    double p1 = double(one) / double(n);
    double p2 = double(two) / double(n);
    double p3 = double(n - zero - one - two) / double(n);
    if (zero)
        ret += calc(zero - 1, one + 1, two) * p0;
    if (one)
        ret += calc(zero, one - 1, two + 1) * p1;
    if (two)
        ret += calc(zero, one, two - 1) * p2;
    ret /= (1 - p3);
    return ret;
}
int main()
{
    cin >> n;
    vector<int> a(n);
    vector<int> c(3);
    rep(i, n)
    {
        cin >> a[i];
        if (a[i] < 3)
        {
            c[a[i]]++;
        }
    }
    rep(i, n) rep(j, n) rep(k, n)
    {
        dp[i][j][k] = -1;
    }
    cout << calc(c[0], c[1], c[2]) << endl;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
    return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
    return (l < r) ? (l = r, true) : false;
}
0