結果

問題 No.174 カードゲーム(Hard)
ユーザー mamekinmamekin
提出日時 2015-04-05 20:28:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 196 ms / 2,000 ms
コード長 1,731 bytes
コンパイル時間 873 ms
コンパイル使用メモリ 101,572 KB
実行使用メモリ 11,912 KB
最終ジャッジ日時 2023-09-21 02:58:05
合計ジャッジ時間 3,184 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 195 ms
11,728 KB
testcase_03 AC 195 ms
11,912 KB
testcase_04 AC 195 ms
11,728 KB
testcase_05 AC 194 ms
11,848 KB
testcase_06 AC 195 ms
11,744 KB
testcase_07 AC 196 ms
11,804 KB
testcase_08 AC 194 ms
11,844 KB
testcase_09 AC 193 ms
11,900 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

void solve(int n, double p, vector<vector<double> >& ans)
{
    ans.assign(n, vector<double>(n, 0.0));

    vector<double> dp(1<<n, 0);
    dp[(1<<n)-1] = 1.0;
    for(int i=(1<<n)-1; i>0; --i){
        bitset<32> bs(i);
        int m = bs.count();

        int j = 0;
        while(!bs[j])
            ++ j;
        if(m == 1){
            ans[n-m][j] += dp[i];
            dp[i^(1<<j)] += dp[i];
        }
        else{
            ans[n-m][j] += dp[i] * p;
            dp[i^(1<<j)] += dp[i] * p;
        }

        for(++j; j<n; ++j){
            if(!bs[j])
                continue;
            ans[n-m][j] += dp[i] * (1.0 - p) / (m - 1);
            dp[i^(1<<j)] += dp[i] * (1.0 - p) / (m - 1);
        }
    }
}

int main()
{
    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];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    vector<vector<double> > p1, p2;
    solve(n, pa, p1);
    solve(n, pb, p2);

    double ans = 0.0;
    for(int x=0; x<n; ++x){
        for(int y=0; y<n; ++y){
            if(a[x] <= b[y])
                continue;
            for(int i=0; i<n; ++i)
                ans += (a[x] + b[y]) * p1[i][x] * p2[i][y];
        }
    }
    printf("%.10f\n", ans);

    return 0;
}
0