結果

問題 No.174 カードゲーム(Hard)
ユーザー tsugutsugutsugutsugu
提出日時 2023-06-16 14:32:05
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 1,798 bytes
コンパイル時間 2,988 ms
コンパイル使用メモリ 253,052 KB
実行使用メモリ 11,852 KB
最終ジャッジ日時 2023-09-06 13:21:49
合計ジャッジ時間 5,481 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 179 ms
11,820 KB
testcase_03 AC 181 ms
11,848 KB
testcase_04 AC 188 ms
11,800 KB
testcase_05 AC 198 ms
11,852 KB
testcase_06 AC 201 ms
11,812 KB
testcase_07 AC 201 ms
11,816 KB
testcase_08 AC 200 ms
11,836 KB
testcase_09 AC 201 ms
11,692 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.hpp"
#else
#define debug(...) 1
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    double pa, pb;
    cin >> n >> pa >> pb;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    auto solve = [&] (double p) -> vector<vector<double>> {
        vector<double> dp(1 << n, 0.0);
        vector<vector<double>> card(n + 1, vector<double>(n, 0.0));
        dp[0] = 1.0;
        for (int bit = 0; bit < (1 << n); bit++) {
            bool mi = true;
            int pc = __builtin_popcount(bit);
            for (int i = 0; i < n; i++) {
                if ((bit >> i) & 1 ^ 1) {
                    int nbit = bit | 1 << i;
                    if (mi) {
                        mi = false;
                        dp[nbit] += dp[bit] * (pc == n - 1 ? 1.0 : p);
                        card[pc + 1][i] += dp[bit] * (pc == n - 1 ? 1.0 : p);
                    } else {
                        dp[nbit] += dp[bit] * (1.0 - p) / (n - pc - 1);
                        card[pc + 1][i] += dp[bit] * (1.0 - p) / (n - pc - 1);
                    }
                }
            }
        }
        return card;
    };
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    auto cardA = solve(pa), cardB = solve(pb);
    debug(cardA);
    double ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                if (a[j] > b[k]) {
                    ans += (double) (a[j] + b[k]) * cardA[i][j] * cardB[i][k];
                }
            }
        }
    }
    cout << fixed << setprecision(15) << ans << '\n';
}
0