結果

問題 No.174 カードゲーム(Hard)
ユーザー __math__math
提出日時 2015-03-27 00:55:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 2,467 bytes
コンパイル時間 836 ms
コンパイル使用メモリ 98,244 KB
実行使用メモリ 11,872 KB
最終ジャッジ日時 2023-09-21 02:25:53
合計ジャッジ時間 2,928 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
11,724 KB
testcase_01 AC 5 ms
11,676 KB
testcase_02 AC 166 ms
11,692 KB
testcase_03 AC 166 ms
11,664 KB
testcase_04 AC 165 ms
11,680 KB
testcase_05 AC 166 ms
11,692 KB
testcase_06 AC 165 ms
11,852 KB
testcase_07 AC 166 ms
11,824 KB
testcase_08 AC 165 ms
11,808 KB
testcase_09 AC 167 ms
11,872 KB
testcase_10 AC 5 ms
11,692 KB
testcase_11 AC 5 ms
11,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <limits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <iterator>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)
#define tenll(x) ((ll)1e##x)

// #pragma comment(linker,"/STACK:36777216")

template<class T> void chmax(T& l, const T r) { l = max(l, r); }
template<class T> void chmin(T& l, const T r) { l = min(l, r); }

double memo[1<<20];
double choice[20][21];
int n;

int popcount(ll x) {
	x = (x & 0x5555555555555555ULL) + ((x & 0xAAAAAAAAAAAAAAAAULL) >> 1);
	x = (x & 0x3333333333333333ULL) + ((x & 0xCCCCCCCCCCCCCCCCULL) >> 2);
	x = (x & 0x0F0F0F0F0F0F0F0FULL) + ((x & 0xF0F0F0F0F0F0F0F0ULL) >> 4);
	return (int)(x * 0x0101010101010101ULL >> 56);
}

void f(double p) {
	memset(memo, 0, sizeof(memo));
	memset(choice, 0, sizeof(choice));
	memo[(1 << n) - 1] = 1.0;
	for (int F = (1 << n) - 1; F > 0; F--) {
		int pop = popcount(F);
		int bit = 0;
		while ((F & (1 << bit)) == 0) bit++;
		double q = memo[F];
		
		if (pop == 1) {
			memo[F ^ (1 << bit)] += q;
			choice[bit][n - pop] += q;
		} else {
			memo[F ^ (1 << bit)] += p * q;
			choice[bit][n - pop] += p * q;
			bit++;
			double r = (1 - p) / (pop - 1);
			for (; bit < n; bit++) {
				if (F & (1 << bit)) {
					memo[F ^ (1 << bit)] += r * q;
					choice[bit][n - pop] += r * q;
				}
			}
		}
	}
}

double a_choice[20][21], b_choice[20][21];
int main() {
	double pa, pb;
	cin >> n >> pa >> pb;
	vector<int> a(n), b(n);
	FOR(i, n) cin >> a[i];
	FOR(i, n) cin >> b[i];
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	f(pa);
	memcpy(a_choice, choice, sizeof(choice));
	f(pb);
	memcpy(b_choice, choice, sizeof(choice));

	double ans = 0;
	FOR(i, n) FOR(j, n) FOR(k, n) {
		double p = a_choice[i][k] * b_choice[j][k];
		double sm = a[i] + b[j];
		if (a[i] > b[j]) {
			ans += p * sm;
		}
	}
	
	printf("%.15lf\n",ans);
}
0