結果

問題 No.174 カードゲーム(Hard)
ユーザー tsutajtsutaj
提出日時 2018-02-07 18:36:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 314 ms / 2,000 ms
コード長 1,578 bytes
コンパイル時間 365 ms
コンパイル使用メモリ 45,360 KB
実行使用メモリ 11,280 KB
最終ジャッジ日時 2023-09-21 03:03:22
合計ジャッジ時間 3,666 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 313 ms
11,280 KB
testcase_03 AC 313 ms
11,228 KB
testcase_04 AC 313 ms
11,240 KB
testcase_05 AC 312 ms
11,232 KB
testcase_06 AC 313 ms
11,228 KB
testcase_07 AC 312 ms
11,148 KB
testcase_08 AC 314 ms
11,184 KB
testcase_09 AC 313 ms
11,252 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <algorithm>
using namespace std;

const int INF = 1 << 28;
int N; double p[2];
int cards[2][20];
double rec[2][20][20];
double dp[1 << 20];

void solve(int t) {
    fill(dp, dp + (1 << N), 0);
    dp[(1 << N) - 1] = 1.0;
    for(int bit=(1<<N)-1; bit>=0; bit--) {
        bool fst = true;
        for(int i=0; i<N; i++) {
            if(bit >> i & 1) {
                int nbit = bit ^ (1 << i), cnt = __builtin_popcount(bit);
                int step = N - cnt;
                if(cnt == 1) {
                    rec[t][i][step] += dp[bit];
                    dp[nbit] += dp[bit];
                    fst = false;
                }
                else {
                    double prob = (fst ? p[t] : (1 - p[t]) / (cnt - 1));
                    rec[t][i][step] += dp[bit] * prob;
                    dp[nbit] += dp[bit] * prob;
                    fst = false;
                }
            }
        }
    }
}

int main() {
    scanf("%d%lf%lf", &N, &p[0], &p[1]);
    for(int i=0; i<N; i++) {
        scanf("%d", &cards[0][i]);
    }
    for(int i=0; i<N; i++) {
        scanf("%d", &cards[1][i]);
    }
    sort(cards[0], cards[0] + N);
    sort(cards[1], cards[1] + N);
    solve(0); solve(1);

    double ans = 0.0;
    for(int step=0; step<N; step++) {
        for(int x=0; x<N; x++) {
            for(int y=0; y<N; y++) {
                if(cards[0][x] < cards[1][y]) continue;
                ans += (cards[0][x] + cards[1][y]) * rec[0][x][step] * rec[1][y][step];
            }
        }
    }
    printf("%.12f\n", ans);
    return 0;
}
0