結果

問題 No.174 カードゲーム(Hard)
ユーザー parukiparuki
提出日時 2016-09-02 09:54:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 243 ms / 2,000 ms
コード長 1,563 bytes
コンパイル時間 1,682 ms
コンパイル使用メモリ 174,344 KB
実行使用メモリ 11,960 KB
最終ジャッジ日時 2023-09-21 02:59:41
合計ジャッジ時間 4,333 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 240 ms
11,844 KB
testcase_03 AC 243 ms
11,852 KB
testcase_04 AC 240 ms
11,960 KB
testcase_05 AC 241 ms
11,852 KB
testcase_06 AC 239 ms
11,808 KB
testcase_07 AC 238 ms
11,756 KB
testcase_08 AC 240 ms
11,892 KB
testcase_09 AC 240 ms
11,940 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

vector<vector<double> > f(int n, double p){
    vector<double> dp(1 << n);
    dp[0] = 1;
    vector<vector<double> > res(n, vector<double>(n));
    rep(S, 1 << n){
        int a = 0, b = 0;
        rep(i, n)b += S >> i & 1;
        rep(i, n)if(!(S >> i & 1)){
            int nS = 1 << i | S;
            double q = 0;
            if(b == n - 1){
                q = 1;
            }else if(!a++){
                q = p;
            } else{
                q = (1 - p) / (n - b - 1);
            }
            dp[nS] += dp[S] * q;
            res[i][b] += q*dp[S];
        }
    }
    return res;
}

int main(){
    int N;
    double PA, PB;
    cin >> N >> PA >> PB;
    vi A(N), B(N);
    rep(i, N)scanf("%d", &A[i]);
    rep(i, N)scanf("%d", &B[i]);
    sort(all(A));
    sort(all(B));

    vector<vector<double> > aa = f(N, PA), bb = f(N, PB);
    
    double ans = 0;
    rep(i, N)rep(j, N)if(A[i] > B[j]){
        int sum = A[i] + B[j];
        rep(k, N){
            ans += sum*aa[i][k] * bb[j][k];
        }
    }
    printf("%0.20f\n", ans);
}
0