結果
| 問題 |
No.174 カードゲーム(Hard)
|
| コンテスト | |
| ユーザー |
pitsu_kyo_pro
|
| 提出日時 | 2019-12-23 13:29:23 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 310 ms / 2,000 ms |
| コード長 | 1,960 bytes |
| コンパイル時間 | 1,770 ms |
| コンパイル使用メモリ | 169,576 KB |
| 実行使用メモリ | 11,876 KB |
| 最終ジャッジ日時 | 2024-09-17 05:43:21 |
| 合計ジャッジ時間 | 4,868 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
ソースコード
#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;
}
pitsu_kyo_pro