結果

問題 No.174 カードゲーム(Hard)
ユーザー pitsu_kyo_propitsu_kyo_pro
提出日時 2019-12-23 13:29:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 308 ms / 2,000 ms
コード長 1,960 bytes
コンパイル時間 1,770 ms
コンパイル使用メモリ 169,336 KB
実行使用メモリ 11,996 KB
最終ジャッジ日時 2023-10-17 07:06:04
合計ジャッジ時間 5,169 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 307 ms
11,996 KB
testcase_03 AC 307 ms
11,996 KB
testcase_04 AC 306 ms
11,996 KB
testcase_05 AC 308 ms
11,996 KB
testcase_06 AC 307 ms
11,996 KB
testcase_07 AC 307 ms
11,996 KB
testcase_08 AC 306 ms
11,996 KB
testcase_09 AC 306 ms
11,996 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1LL << 60;
constexpr int INF = 1000000007;
const double INFD = 1e100;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int N;
double p[2];
int cards[2][20];
double rec[2][20][20];
double dp[(1<<20)];
void solve(int t){
  fill(dp, dp+(1<<N),0);
  dp[(1<<N)-1] = 1.0;
  for(int bit=(1<<N)-1; bit>=0; bit--){
    bool fst=true;
    for(int i=0; i<N; i++){
      if(bit >> i & 1){
        int nbit = bit ^ (1 << i);
        int cnt = __builtin_popcount(bit);
        int step = N-cnt;
        if(cnt==1){
          rec[t][i][step] += dp[bit];
          dp[nbit] += dp[bit];
        }else{
          double prob = (fst ? p[t] : (1-p[t])/(cnt-1));
          rec[t][i][step] += dp[bit] * prob;
          dp[nbit] += dp[bit] * prob;
          fst = false;
        }
      }
    }
  }
}

int main(){
  cin >> N >> p[0] >> p[1];
  for(int i=0; i<N; i++){
    cin >> cards[0][i];
  }
  for(int i=0; i<N; i++){
    cin >> cards[1][i];
  }
  sort(cards[0],cards[0]+N);
  sort(cards[1],cards[1]+N);
  solve(0);
  solve(1);
  double ans=0.0;
  for(int step=0; step<N; step++){
    for(int x=0; x<N; x++){
      for(int y=0; y<N; y++){
        if(cards[0][x] < cards[1][y]){
          continue;
        }
        ans += (cards[0][x] + cards[1][y]) * rec[0][x][step] * rec[1][y][step];
      }
    }
  }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}
0