結果

問題 No.174 カードゲーム(Hard)
ユーザー keikei
提出日時 2018-09-09 11:32:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 3,281 bytes
コンパイル時間 2,285 ms
コンパイル使用メモリ 176,788 KB
実行使用メモリ 380,776 KB
最終ジャッジ日時 2023-08-24 18:15:07
合計ジャッジ時間 6,214 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://yukicoder.me/problems/no/174>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

typedef long double ld;

vector<vector<ld>> get(vector<int>& V,ld P){
    int N = (int)V.size();
    sort(V.begin(),V.end());
    vector<vector<ld>> dp(1<<N,vector<ld>(N,0));
    dp[1<<0][0] = P;
    for(int i = 1; i < N;i++) dp[1<<i][i] = (1-P)/(N-1);
    for(int i = 0; i < (1<<N);i++){
        for(int j = 0; j < N;j++){
            if(dp[i][j] == 0) continue;
            int leafN = N - __builtin_popcount(i);
            if(leafN == 1){
                for(int k = 0; k < N;k++){
                    if((i>>k)&1)continue;
                    dp[i|(1<<k)][k] += dp[i][j];
                }
            }else{
                bool first = true;
                for(int k = 0; k < N;k++){
                    if((i>>k)&1)continue;
                    if(first){
                        dp[i|(1<<k)][k] += dp[i][j]*P;
                        first = false;
                    }else{
                        dp[i|(1<<k)][k] += dp[i][j]*(1-P)/(leafN-1);
                    }
                }
            }
        }
    }
    
    vector<vector<ld>> ret(N+1,vector<ld>(N));
    for(int i = 0; i < (1<<N);i++){
        for(int j = 0; j < N;j++){
            int SZ = __builtin_popcount(i);
            ret[SZ][j] += dp[i][j];
        }
    }
    return ret;
}
ld solve(){
    ld res = 0;
    int N; cin >> N;
    ld P[2]; for(int i = 0; i < 2;i++) cin >> P[i];
    vector<int> A(N),B(N);
    for(auto& in:A) cin >> in;
    for(auto& in:B) cin >> in;
    
    auto infoA = get(A,P[0]);
    auto infoB = get(B,P[1]);
    
    for(int i = 1; i <= N;i++){
        for(int j = 0;j<N;j++){
            ld selectA = infoA[i][j];
            for(int k = 0;k<N;k++){
                if(A[j]>B[k]){
                    ld selectB = infoB[i][k];
                    ld score = A[j]+B[k];
                    res += selectA*selectB*score;
                }
            }
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(12) << solve() << endl;
    return 0;
}
0