結果

問題 No.174 カードゲーム(Hard)
ユーザー 沙耶花沙耶花
提出日時 2021-11-03 17:05:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 312 ms / 2,000 ms
コード長 1,306 bytes
コンパイル時間 4,927 ms
コンパイル使用メモリ 260,292 KB
実行使用メモリ 19,968 KB
最終ジャッジ日時 2024-04-21 08:32:17
合計ジャッジ時間 8,275 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 305 ms
19,840 KB
testcase_03 AC 310 ms
19,968 KB
testcase_04 AC 312 ms
19,768 KB
testcase_05 AC 310 ms
19,696 KB
testcase_06 AC 306 ms
19,940 KB
testcase_07 AC 307 ms
19,840 KB
testcase_08 AC 303 ms
19,704 KB
testcase_09 AC 308 ms
19,708 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 2000000000


int main(){	
	
	int N;
	cin>>N;
	double Pa,Pb;
	cin>>Pa>>Pb;
	
	vector<double> dpa(1<<N,0.0),dpb(1<<N,0.0);
	dpa[0] = 1.0;
	dpb[0] = 1.0;
	vector pa(N,vector<double>(N,0.0));
	vector pb(N,vector<double>(N,0.0));
	
	rep(i,1<<N){
		bool f = true;
		rep(j,N){
			if((i>>j)&1)continue;
			int n = __builtin_popcount(i);
			double pp;
			if(n==N-1)pp = 1.0;
			else if(f)pp = Pa;
			else pp = (1.0-Pa) * (1.0 / (N-n-1));
			f = false;
			pp *= dpa[i];
			pa[n][j] += pp;
			dpa[i|(1<<j)] += pp;
		}
	}
	rep(i,1<<N){
		bool f = true;
		rep(j,N){
			if((i>>j)&1)continue;
			int n = __builtin_popcount(i);
			double pp;
			if(n==N-1)pp = 1.0;
			else if(f)pp = Pb;
			else pp = (1.0-Pb) * (1.0 / (N-n-1));
			f = false;
			pp *= dpb[i];
			pb[n][j] += pp;
			dpb[i|(1<<j)] += pp;
		}
	}
	
	vector<int> a(N),b(N);
	rep(i,N)cin>>a[i];
	rep(i,N)cin>>b[i];
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	
	double ans = 0.0;
	rep(i,N){
		rep(j,N){
			if(a[i]<b[j])continue;
			rep(k,N){
				ans += pa[k][i] * pb[k][j] * (a[i]+b[j]);
			}
		}
	}
	
	cout<<fixed<<setprecision(15)<<ans<<endl;
	
	return 0;
	
}
0