結果

問題 No.133 カードゲーム
ユーザー momoyuumomoyuu
提出日時 2023-10-24 17:58:55
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,281 bytes
コンパイル時間 3,331 ms
コンパイル使用メモリ 255,076 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 17:59:01
合計ジャッジ時間 4,029 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false); 

    int n;
    cin>>n;
    vector<vector<vector<double>>> dp(1<<n,vector<vector<double>>(1<<n,vector<double>(10,0)));
    dp[0][0][4] = 1;
    vector<int> a(n),b(n);
    for(int i = 0;i<n;i++) cin>>a[i];
    for(int i = 0;i<n;i++) cin>>b[i];

    for(int i = 0;i<1<<n;i++){
        for(int j = 0;j<1<<n;j++){
            for(int k = 1;k<9;k++){
                int ra = n - __builtin_popcount(i);
                int rb = n - __builtin_popcount(j);
                if(ra!=rb) continue;
                if(ra==0) continue;
                for(int l = 0;l<n;l++) if(~i>>l&1){
                    for(int m = 0;m<n;m++) if(~j>>m&1){
                        double p = dp[i][j][k] / (double)(ra*rb);
                        if(a[l]>b[m]) dp[i|(1<<l)][j|(1<<m)][k+1] += p;
                        else if(a[l]<b[m]) dp[i|(1<<l)][j|(1<<m)][k-1] += p;
                        else dp[i|(1<<l)][j|(1<<m)][k] += p;
                    }
                }
            }   
        }
    }
    double ans = 0;
    int mask = (1<<n) - 1;
    for(int i = 5;i<10;i++){
        ans += dp[mask][mask][i];
    }
    cout<<setprecision(30)<<fixed<<ans<<endl;
}

0