結果

問題 No.174 カードゲーム(Hard)
ユーザー 👑 kmjpkmjp
提出日時 2015-03-27 00:40:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 220 ms / 2,000 ms
コード長 1,794 bytes
コンパイル時間 1,287 ms
コンパイル使用メモリ 148,992 KB
実行使用メモリ 20,288 KB
最終ジャッジ日時 2023-09-21 02:25:31
合計ジャッジ時間 3,796 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,756 KB
testcase_01 AC 2 ms
7,728 KB
testcase_02 AC 216 ms
20,284 KB
testcase_03 AC 217 ms
20,140 KB
testcase_04 AC 215 ms
20,144 KB
testcase_05 AC 216 ms
20,160 KB
testcase_06 AC 217 ms
20,288 KB
testcase_07 AC 216 ms
20,188 KB
testcase_08 AC 220 ms
20,160 KB
testcase_09 AC 216 ms
20,148 KB
testcase_10 AC 3 ms
7,748 KB
testcase_11 AC 2 ms
7,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<to;x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,T;
double P[2];
int A[30],B[30];
double PP[2][1<<21];
double PQ[2][21][21];
double win[21][21];
double DP[2][40*10000+1];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>P[0]>>P[1];
	FOR(i,N) cin>>A[i];
	FOR(i,N) cin>>B[i];
	sort(A,A+N);
	sort(B,B+N);
	
	PP[0][0]=PP[1][0]=1;
	FOR(i,N) FOR(x,1<<N) if(__builtin_popcount(x)==i) {
		int f=1;
		FOR(j,N) if((x & (1<<j))==0) {
			if(i==N-1) {
				PP[0][x | (1<<j)] += PP[0][x];
				PP[1][x | (1<<j)] += PP[1][x];
				PQ[0][j][i] += PP[0][x];
				PQ[1][j][i] += PP[1][x];
			}
			else {
				if(f) {
					PP[0][x | (1<<j)] += PP[0][x] * P[0];
					PP[1][x | (1<<j)] += PP[1][x] * P[1];
					PQ[0][j][i] += PP[0][x] * P[0];
					PQ[1][j][i] += PP[1][x] * P[1];
					f=0;
				}
				else {
					PP[0][x | (1<<j)] += PP[0][x] * (1-P[0])/(N-1-i);
					PP[1][x | (1<<j)] += PP[1][x] * (1-P[1])/(N-1-i);
					PQ[0][j][i] += PP[0][x] * (1-P[0])/(N-1-i);
					PQ[1][j][i] += PP[1][x] * (1-P[1])/(N-1-i);
				}
			}
		}
	}
	
	FOR(i,N) FOR(x,N) FOR(y,N) win[x][y] += PQ[0][x][i]*PQ[1][y][i];
	
	double ret=0;
	FOR(x,N) {
		FOR(y,N) if(A[x]>B[y]) ret+=(A[x]+B[y])*win[x][y];
	}
	_P("%.12lf\n",ret);
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0