結果

問題 No.174 カードゲーム(Hard)
ユーザー eitahoeitaho
提出日時 2015-03-27 16:06:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 511 ms / 2,000 ms
コード長 1,999 bytes
コンパイル時間 655 ms
コンパイル使用メモリ 78,408 KB
実行使用メモリ 167,544 KB
最終ジャッジ日時 2023-09-21 02:57:13
合計ジャッジ時間 5,790 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
167,380 KB
testcase_01 AC 68 ms
167,404 KB
testcase_02 AC 510 ms
167,372 KB
testcase_03 AC 508 ms
167,404 KB
testcase_04 AC 511 ms
167,400 KB
testcase_05 AC 510 ms
167,544 KB
testcase_06 AC 509 ms
167,488 KB
testcase_07 AC 511 ms
167,432 KB
testcase_08 AC 508 ms
167,376 KB
testcase_09 AC 507 ms
167,448 KB
testcase_10 AC 70 ms
167,436 KB
testcase_11 AC 70 ms
167,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <climits>
#include <numeric>
#include <functional>
#include <time.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)a; i <= (int)b; i++)
template<class T> void checkmin(T &a, T b) { if (b < a) a = b; }
template<class T> void checkmax(T &a, T b) { if (b > a) a = b; }


const int MaxN = 20;
int N;
double PA, PB;
int A[MaxN], B[MaxN];
double bitdp[1 << MaxN][MaxN];
double AtA[MaxN][MaxN], AtB[MaxN][MaxN]; // who, at

int bitcount(int x) { int c = 0; while (x != 0) { c++; x &= x - 1; } return c; }

void checkProb(double selectMinProb, double res[MaxN][MaxN]) {
    memset(bitdp, 0, sizeof(bitdp));
    bitdp[0][0] = 1;

    rep(mask, 1 << N) {
        int num = bitcount(mask);
        int rem = N - num;
        int min = -1;
        double currProb = 0;
        rep(i, N) {
            currProb += bitdp[mask][i];
            if (min == -1 && (mask >> i & 1) == 0) min = i;
        }
        rep(next, N) if ((mask >> next & 1) == 0) {
            double selectProb = (rem == 1) ? 1 : (next == min) ? selectMinProb : (1 - selectMinProb) / (rem - 1);
            double p = currProb * selectProb;
            bitdp[mask | 1 << next][next] += p;
            res[next][num] += p;
        }
    }
}

void solve() {
    sort(A, A + N);
    sort(B, B + N);
    checkProb(PA, AtA);
    checkProb(PB, AtB);
    double ans = 0;

    rep(ai, N) rep(bi, N) if (A[ai] > B[bi]) rep(pos, N) {
        ans += (A[ai] + B[bi]) * AtA[ai][pos] * AtB[bi][pos];
    }
    printf("%.12f\n", ans);
}

int main() {
    cin >> N >> PA >> PB;
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    solve();
    return 0;
}
0