結果

問題 No.174 カードゲーム(Hard)
ユーザー なおなお
提出日時 2015-03-27 03:04:18
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 244 ms / 2,000 ms
コード長 2,160 bytes
コンパイル時間 1,777 ms
コンパイル使用メモリ 150,096 KB
実行使用メモリ 24,608 KB
最終ジャッジ日時 2023-09-21 02:51:51
合計ジャッジ時間 4,042 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,688 KB
testcase_01 AC 2 ms
5,556 KB
testcase_02 AC 243 ms
24,520 KB
testcase_03 AC 244 ms
24,600 KB
testcase_04 AC 243 ms
24,604 KB
testcase_05 AC 243 ms
24,608 KB
testcase_06 AC 242 ms
24,588 KB
testcase_07 AC 242 ms
24,436 KB
testcase_08 AC 243 ms
24,548 KB
testcase_09 AC 242 ms
24,516 KB
testcase_10 AC 2 ms
5,680 KB
testcase_11 AC 2 ms
5,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))
#define FOR(i, f, t)        for(int(i)=(f);(i)<(t);(++i))
#define EACH(it, c)         for(auto it=(c).begin();it!=(c).end();++it)

int N;
double P[2];
int a[22],b[22];
int res = 0;

double p[2][1<<21];  // p[a/b][使用済みカード状態ビット] = 確率
double q[2][22][22]; // q[a/b][i番目のカードを][j回目に出す] = 確率

VI pc[22];

int main(){
    do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0);
    cin >> N >> P[0] >> P[1];

    REP(i,N) cin >> a[i]; sort(a,a+N);
    REP(i,N) cin >> b[i]; sort(b,b+N);

    REP(i,1<<N) pc[__builtin_popcount(i)].push_back(i);

    p[0][0] = p[1][0] = 1;
    REP(t,2) REP(i,N){
        EACH(it,pc[i]){
            const int &j = *it;
            bool first = true;
            REP(k,N){
                if((j>>k)&1) continue;
                if(i < N-1){
                    if(first){
                        first = false;
                        double pp = p[t][j] * P[t]; // 最小値が選ばれる確率
                        p[t][j|(1<<k)] += pp;
                        q[t][k][i] += pp;
                    } else {
                        double pp = p[t][j] * (1-P[t])/(N-i-1); // (残り枚数-1)で割る
                        p[t][j|(1<<k)] += pp;
                        q[t][k][i] += pp;
                    }
                } else {
                    // 最後のカード(無条件で選ぶ)
                    double pp = p[t][j];
                    p[t][j|(1<<k)] += pp;
                    q[t][k][i] += pp;
                }
            }
        }
    }

    double res = 0;
    REP(i,N){   // i枚目
        REP(ai,N){ // Aが出すカード
            REP(bi,N){ // Bが出すカード
                if(a[ai] > b[bi]){
                    int score = a[ai]+b[bi];
                    res += score * q[0][ai][i] * q[1][bi][i];
                }
            }
        }
    }
    cout << fixed << setprecision(15) << res << endl;
    return 0;
}
0