結果

問題 No.174 カードゲーム(Hard)
ユーザー nsd_fbnsd_fb
提出日時 2015-03-27 00:55:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,868 ms / 2,000 ms
コード長 1,853 bytes
コンパイル時間 1,801 ms
コンパイル使用メモリ 160,820 KB
実行使用メモリ 19,572 KB
最終ジャッジ日時 2023-09-11 10:41:15
合計ジャッジ時間 16,429 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1,685 ms
19,452 KB
testcase_03 AC 1,744 ms
19,364 KB
testcase_04 AC 1,812 ms
19,460 KB
testcase_05 AC 1,865 ms
19,572 KB
testcase_06 AC 1,868 ms
19,300 KB
testcase_07 AC 1,764 ms
19,316 KB
testcase_08 AC 1,735 ms
19,348 KB
testcase_09 AC 1,681 ms
19,448 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <sys/time.h>

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif

using namespace std;

#define REP(i, a, b) for(int i = (a); i < int(b); ++i)
#define rep(i, n) REP(i, 0, n)
#define ALL(x) begin(x), end(x)

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

vector<vector<double>> calc(int n, double p) {
	const double q = 1.0 - p;

	vector<vector<double>> res(n, vector<double>(n, 0));
	unordered_map<int, double> dp;
	dp[(1 << n) - 1] = 1.0;

	for(int i = 0; i < n; ++i) {
		const int num = n - i;
		unordered_map<int, double> next_dp;

		double sum = 0.0;
		for(const auto &e : dp) {
			const auto card = e.first;
			const auto cp = e.second;

			bool first = true;

			for(int j = 0; j < n; ++j) {
				if((card >> j) & 1) {
					double np;
					if(num == 1) {
						np = cp;
					}
					else if(first) {
						np = cp * p;
					}
					else {
						np = cp * q / (num - 1);
					}

					first = false;
					res[j][i] += np;
					next_dp[card ^ (1 << j)] += np;
				}
			}

			sum += cp;
		}

		assert(abs(sum - 1.0) < 1e-8);

		dp = move(next_dp);
	}

	return res;
}

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout.setf(ios::fixed);
	cout.precision(10);

	int n;
	double pa, pb;

	cin >> n >> pa >> pb;

	vector<int> a(n);
	vector<int> b(n);

	for(auto &e : a) cin >> e;
	for(auto &e : b) cin >> e;

	sort(begin(a), end(a));
	sort(begin(b), end(b));

	const auto pa_card = calc(n, pa);
	const auto pb_card = calc(n, pb);

	double ans = 0.0;
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			if(a[i] < b[j]) continue;

			for(int k = 0; k < n; ++k) {
				ans += (a[i] + b[j]) * pa_card[i][k] * pb_card[j][k];
			}
		}
	}

	cout << ans << endl;

	return EXIT_SUCCESS;
}
0