結果

問題 No.174 カードゲーム(Hard)
ユーザー omochana1omochana1
提出日時 2015-03-27 01:15:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 310 ms / 2,000 ms
コード長 2,066 bytes
コンパイル時間 852 ms
コンパイル使用メモリ 85,864 KB
実行使用メモリ 20,064 KB
最終ジャッジ日時 2023-09-21 02:43:22
合計ジャッジ時間 3,819 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,732 KB
testcase_01 AC 2 ms
5,732 KB
testcase_02 AC 308 ms
19,948 KB
testcase_03 AC 309 ms
20,036 KB
testcase_04 AC 309 ms
20,016 KB
testcase_05 AC 309 ms
20,036 KB
testcase_06 AC 309 ms
19,908 KB
testcase_07 AC 308 ms
19,952 KB
testcase_08 AC 308 ms
20,064 KB
testcase_09 AC 310 ms
20,044 KB
testcase_10 AC 2 ms
5,564 KB
testcase_11 AC 2 ms
5,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <string.h>
#include <map>
#include <fstream>
#include <functional>
#include <bitset>
#include <stack>
#include <set>
#include <climits>
#define MAX_N 100010
#define LOG 21
#define PI 3.141592653589
#define EPS 1e-6
#define MOD 1000000007
#define YJSNPI 810
#define INF (1 << 30)
#define ADD(a, b) a = (a + (ll)b) % MOD
#define MUL(a, b) a = (a * (ll)b) % MOD
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define x first
#define y second
#define REP(i, a, b) for(int i = a; i < b; i++)
#define RER(i, a, b) for(int i = a - 1; i >= b; i--)

using namespace std;

typedef long long ll;
typedef pair<ll, int> pi;

void debug() {cout << endl; }

template<class FIRST, class... REST>
void debug(FIRST arg, REST... rest) { cout << arg << " "; debug(rest...); }

template<class T>
void showary(T begin, T end) { 
	while(begin != end) { cout << *begin << " "; begin++; } cout << endl; }

double pa[50][50];
double pb[50][50];
double wina[50], winb[50];
double dp1[1 << 20];
double dp2[1 << 20];
int va[50], vb[50];

int N;
double A, B;

void solve(double *dp, double (*p)[50], double A) {
	dp[0] = 1.0;
	REP(bit, 0, ((1 << N) - 1)) {
		int cnt = 0, minat = -1;
		REP(i, 0, N) {
			if(bit & (1 << i)) cnt++;
			else if(minat == -1) minat = i;
		}
		if(cnt == N - 1) p[cnt][minat] += dp[bit];
		else p[cnt][minat] += dp[bit] * A;
		dp[bit | (1 << minat)] += dp[bit] * A;
		REP(i, 0, N) {
			if((bit & (1 << i)) || minat == i) continue;
			p[cnt][i] += dp[bit] * (1.0 - A) / (N - cnt - 1.0);
			dp[bit | (1 << i)] += dp[bit] * (1.0 - A) / (N - cnt - 1.0);
		}
	}
}
int main() {
	cin >> N >> A >> B;
	REP(i, 0, N) cin >> va[i];
	REP(i, 0, N) cin >> vb[i];
	sort(va, va + N);
	sort(vb, vb + N);
	solve(dp1, pa, A);
	solve(dp2, pb, B);
	double res = 0;
	REP(i, 0, N) {
		REP(j, 0, N) {
			REP(k, 0, N) {
				if(va[j] > vb[k]) {
					res += pa[i][j] * pb[i][k] * (va[j] + vb[k]);
				}
			}
		}
	}
	printf("%.10f\n", res);
}
0