結果

問題 No.108 トリプルカードコンプ
ユーザー uenokuuenoku
提出日時 2020-04-28 20:51:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,543 bytes
コンパイル時間 1,655 ms
コンパイル使用メモリ 168,288 KB
実行使用メモリ 8,216 KB
最終ジャッジ日時 2023-08-16 17:53:05
合計ジャッジ時間 3,009 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 9 ms
8,216 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 WA -
testcase_13 AC 3 ms
4,384 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 6 ms
6,420 KB
testcase_19 AC 3 ms
4,428 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 5 ms
5,064 KB
testcase_22 AC 1 ms
4,380 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]]++;
        }
    }
    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