結果

問題 No.174 カードゲーム(Hard)
ユーザー hashiryohashiryo
提出日時 2019-05-22 15:34:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 345 ms / 2,000 ms
コード長 2,041 bytes
コンパイル時間 1,968 ms
コンパイル使用メモリ 100,564 KB
実行使用メモリ 20,248 KB
最終ジャッジ日時 2023-10-17 11:14:46
合計ジャッジ時間 4,301 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <float.h>
#include <random>

#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
#define debugArrayP(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge].first<< " " << x[hoge].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;

int N;
double P[2];
double dp[2][(1<<20)+10];
double dp2[2][30][30];
int card[2][30];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>N;
  cin>>P[0]>>P[1];
  repeat(c,2)repeat(i,N)cin>>card[c][i];
  repeat(c,2)sort(card[c],card[c]+N);
  //debugArray(card[0],N);
  //debugArray(card[1],N);
  dp[0][(1<<N)-1] =dp[1][(1<<N)-1]= 1;
  repeat(c,2){
    for(int b=(1<<N)-2;b>0;b--){
      int cnt=__builtin_popcount(b);
      int minb = __builtin_ffs(b)-1;
      repeat(i,N)if(!((b>>i)&1)){
        dp[c][b] += ((i<minb)? P[c]:(1.0-P[c])/cnt)*dp[c][b|(1<<i)];
      }
    }
  }
  //debugArray(dp[0],((1<<N)));
  repeat(c,2){
    for(int b=(1<<N)-1;b>0;b--){
      int t=N-__builtin_popcount(b);
      int minb = __builtin_ffs(b)-1;
      repeat(i,N)if((b>>i)&1){
        dp2[c][t][i] += (t==N-1? 1:(i==minb)? P[c]:(1.0-P[c])/(N-t-1))*dp[c][b];
      }
    }
  }
  double ans = 0;
  repeat(t,N){
    repeat(a,N){
      repeat(b,N){
        if(card[0][a] > card[1][b]){
          ans += dp2[0][t][a]*dp2[1][t][b]*(card[0][a]+card[1][b]);
        }
      }
    }
  }
  printf("%.10lf\n",ans);
  return 0;
}
0