結果
| 問題 |
No.174 カードゲーム(Hard)
|
| コンテスト | |
| ユーザー |
chocorusk
|
| 提出日時 | 2020-02-03 04:14:55 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 208 ms / 2,000 ms |
| コード長 | 2,213 bytes |
| コンパイル時間 | 1,199 ms |
| コンパイル使用メモリ | 112,804 KB |
| 実行使用メモリ | 20,096 KB |
| 最終ジャッジ日時 | 2024-09-18 21:37:47 |
| 合計ジャッジ時間 | 3,455 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
ソースコード
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
double dpa[1<<20], dpb[1<<20];
int main()
{
int n;
double pa, pb;
cin>>n>>pa>>pb;
int a[20], b[20];
for(int i=0; i<n; i++){
cin>>a[i];
}
for(int i=0; i<n; i++){
cin>>b[i];
}
sort(a, a+n);
sort(b, b+n);
double qa[20][21]={}, qb[20][21]={};
for(int i=1; i<n; i++){
dpa[1<<i]=(1-pa)/(n-1);
dpb[1<<i]=(1-pb)/(n-1);
qa[i][1]+=(1-pa)/(n-1);
qb[i][1]+=(1-pb)/(n-1);
}
if(n>1){
dpa[1]=pa, dpb[1]=pb;
qa[0][1]+=pa, qb[0][1]+=pb;
}else{
dpa[1]=dpb[1]=1;
qa[0][1]+=1, qb[0][1]+=1;
}
for(int i=1; i<(1<<n)-1; i++){
double s=dpa[i]; int c=n-popcount(i);
bool myon=0;
for(int j=0; j<n; j++){
if(i&(1<<j)) continue;
if(!myon){
if(c>1){
dpa[i^(1<<j)]+=s*pa;
qa[j][n-c+1]+=s*pa;
}else{
dpa[i^(1<<j)]+=s;
qa[j][n-c+1]+=s;
}
}else{
dpa[i^(1<<j)]+=s*(1-pa)/(c-1);
qa[j][n-c+1]+=s*(1-pa)/(c-1);
}
myon=1;
}
}
for(int i=1; i<(1<<n)-1; i++){
double s=dpb[i]; int c=n-popcount(i);
bool myon=0;
for(int j=0; j<n; j++){
if(i&(1<<j)) continue;
if(!myon){
if(c>1){
dpb[i^(1<<j)]+=s*pb;
qb[j][n-c+1]+=s*pb;
}else{
dpb[i^(1<<j)]+=s;
qb[j][n-c+1]+=s;
}
}else{
dpb[i^(1<<j)]+=s*(1-pb)/(c-1);
qb[j][n-c+1]+=s*(1-pb)/(c-1);
}
myon=1;
}
}
double ans=0;
for(int i=1; i<=n; i++){
for(int j=0; j<n; j++){
for(int k=0; k<n; k++){
if(a[j]<b[k]) continue;
ans+=(a[j]+b[k])*qa[j][i]*qb[k][i];
}
}
}
printf("%.10lf\n", ans);
return 0;
}
chocorusk