結果

問題 No.174 カードゲーム(Hard)
ユーザー EmKjpEmKjp
提出日時 2015-03-28 10:51:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 329 ms / 2,000 ms
コード長 2,117 bytes
コンパイル時間 684 ms
コンパイル使用メモリ 90,368 KB
実行使用メモリ 11,880 KB
最終ジャッジ日時 2023-09-21 02:57:24
合計ジャッジ時間 3,983 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 325 ms
11,880 KB
testcase_03 AC 324 ms
11,740 KB
testcase_04 AC 325 ms
11,852 KB
testcase_05 AC 325 ms
11,724 KB
testcase_06 AC 326 ms
11,728 KB
testcase_07 AC 326 ms
11,788 KB
testcase_08 AC 322 ms
11,824 KB
testcase_09 AC 329 ms
11,832 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<numeric>
#include<functional>
#include<complex>

using namespace std;
#define BET(a,b,c) ((a)<=(b)&&(b)<(c))
#define FOR(i,n) for(int i=0,i##_end=(int(n));i<i##_end;i++)
#define SZ(x) (int)(x.size())
#define ALL(x) (x).begin(),(x).end()
#define MP make_pair
#define FOR_EACH(it,v) for(__typeof(v.begin()) it=v.begin(),it_end=v.end() ; it != it_end ; it++)
typedef vector<int> VI;
typedef vector<VI> VVI;

vector<vector<double> > getTable(VI A, double p){
    int n = SZ(A);
    vector<double> prob(1<<n);
    vector<vector<double> > useP(n, vector<double>(n)); 
    prob[0] = 1.0;
    for(int b=0;b<(1<<n);b++){
        if(prob[b] == 0) continue;
        int minp = 1<<28;
        int minIndex = -1;
        int rem = 0;
        FOR(i,n){
            if(b & (1<<i)) continue;
            rem++;
            if(minp > A[i]) {
                minp = A[i];
                minIndex = i;
            }
        }
        if(rem == 1){
            prob[b | (1<<minIndex)] += prob[b];
            useP[n - rem][minIndex] += prob[b];
        }else{
            FOR(i,n){
                if(b & (1<<i)) continue;
                if(i == minIndex){
                    prob[b | (1<<i)] += prob[b] * p;
                    useP[n - rem][i] += prob[b] * p;
                }else {
                    prob[b | (1<<i)] += prob[b] * (1.0 - p) / (rem - 1);
                    useP[n - rem][i] += prob[b] * (1.0 - p) / (rem - 1);
                }
            }
        }
    }
    return useP;
}

int main()
{
    int N;
    double pa,pb;
    cin>>N>>pa>>pb;
    VI A(N); FOR(i,N) cin>>A[i];
    VI B(N); FOR(i,N) cin>>B[i];

    auto t1 = getTable(A, pa);
    auto t2 = getTable(B, pb);
    double ans = 0 ;

    FOR(t,N){
        FOR(i,N) FOR(j,N){
            if(A[i] > B[j]){
                ans += t1[t][i] * t2[t][j] * (A[i] + B[j]);
            }
        }
    }

    printf("%.10f\n", ans);
    
    return 0;
}
0