結果

問題 No.108 トリプルカードコンプ
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-09-27 22:11:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 217 ms / 5,000 ms
コード長 1,531 bytes
コンパイル時間 1,707 ms
コンパイル使用メモリ 176,748 KB
実行使用メモリ 17,368 KB
最終ジャッジ日時 2023-08-13 12:33:17
合計ジャッジ時間 3,271 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 217 ms
17,368 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 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,376 KB
testcase_13 AC 11 ms
4,564 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 7 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 154 ms
13,704 KB
testcase_19 AC 39 ms
6,872 KB
testcase_20 AC 15 ms
4,952 KB
testcase_21 AC 96 ms
10,428 KB
testcase_22 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

namespace {

    typedef long double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        auto i = vs.begin();
        os << "[" << *i;
        for (++i; i != vs.end(); ++i) os << " " << *i;
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    int N;
    vector<int> A;
    void input() {
        cin >> N;
        A.resize(N);
        cin >> A;
    }

    map< tuple<int,int,int>, real > cache;
    real f(int a, int b, int c) {
        if (a < 0 || b < 0 || c < 0) return 0;
        real s = a + b + c;
        if (s == 0) return 0;
        auto key = make_tuple(a, b, c);
        if (cache.count(key)) {
            return cache[key];
        }
        //cerr << a << " " << b << " " << c << " -> " <<  (N / s) + (a / s * f(a - 1, b + 1, c) + b / s * f(a, b - 1, c + 1) + c / s * f(a, b, c - 1)) << endl;
        return cache[key] = (N / s) + (a / s * f(a - 1, b + 1, c) + b / s * f(a, b - 1, c + 1) + c / s * f(a, b, c - 1));
    }
    void solve() {
        vector<int> r(4, 0);
        for (int i = 0; i < N; i++) {
            int k = max(0, 3 - A[i]);
            r[k]++;
        }
        cout << fixed << setprecision(12) << f(r[3], r[2], r[1]) << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}

0