結果

問題 No.174 カードゲーム(Hard)
ユーザー t98slidert98slider
提出日時 2022-07-15 05:13:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 1,661 bytes
コンパイル時間 2,592 ms
コンパイル使用メモリ 174,216 KB
実行使用メモリ 19,888 KB
最終ジャッジ日時 2023-09-09 06:31:38
合計ジャッジ時間 3,732 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 142 ms
19,776 KB
testcase_03 AC 143 ms
19,608 KB
testcase_04 AC 142 ms
19,652 KB
testcase_05 AC 142 ms
19,888 KB
testcase_06 AC 142 ms
19,608 KB
testcase_07 AC 141 ms
19,560 KB
testcase_08 AC 142 ms
19,776 KB
testcase_09 AC 142 ms
19,604 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    double pa, pb;
    scanf("%d %lf %lf", &n, &pa, &pb);
    vector<int> a(n), b(n);
    vector<vector<double>> A(n, vector<double>(n)), B(n, vector<double>(n));
    for(auto &&v: a)cin >> v;
    for(auto &&v: b)cin >> v;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    vector<double> dp1(1 << n), dp2(1 << n);
    dp1[0] = dp2[0] = 1;
    for(int i = 0; i < (1 << n); i++){
        int cnt = __builtin_popcount(i);
        for(int j = 0, flag = 1; j < n; j++){
            if(~i >> j & 1){
                if(flag){
                    if(cnt + 1 == n){
                        A[j][cnt] += dp1[i];
                        B[j][cnt] += dp2[i];
                        continue;
                    }
                    A[j][cnt] += dp1[i] * pa;
                    dp1[i | (1 << j)] += dp1[i] * pa;
                    B[j][cnt] += dp2[i] * pb;
                    dp2[i | (1 << j)] += dp2[i] * pb;
                    flag = 0;
                }else{
                    A[j][cnt] += dp1[i] * (1 - pa) / (n - cnt - 1);
                    dp1[i | (1 << j)] += dp1[i] * (1 - pa) / (n - cnt - 1);
                    B[j][cnt] += dp2[i] * (1 - pb) / (n - cnt - 1);
                    dp2[i | (1 << j)] += dp2[i] * (1 - pb) / (n - cnt - 1);
                } 
            }
        }
    }
    double ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(a[i] < b[j])continue;
            for(int k = 0; k < n; k++){
                ans += (a[i] + b[j]) * A[i][k] * B[j][k];
            }
        }
    }
    printf("%.15lf\n", ans);
}
0