結果

問題 No.174 カードゲーム(Hard)
ユーザー chocoruskchocorusk
提出日時 2020-02-03 04:14:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 193 ms / 2,000 ms
コード長 2,213 bytes
コンパイル時間 1,066 ms
コンパイル使用メモリ 113,852 KB
実行使用メモリ 20,252 KB
最終ジャッジ日時 2023-10-19 01:39:38
合計ジャッジ時間 3,242 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,916 KB
testcase_01 AC 2 ms
5,916 KB
testcase_02 AC 192 ms
20,252 KB
testcase_03 AC 192 ms
20,252 KB
testcase_04 AC 191 ms
20,252 KB
testcase_05 AC 192 ms
20,252 KB
testcase_06 AC 193 ms
20,252 KB
testcase_07 AC 193 ms
20,252 KB
testcase_08 AC 191 ms
20,252 KB
testcase_09 AC 192 ms
20,252 KB
testcase_10 AC 2 ms
5,916 KB
testcase_11 AC 2 ms
5,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0