結果
| 問題 | No.133 カードゲーム | 
| コンテスト | |
| ユーザー |  momoyuu | 
| 提出日時 | 2023-10-24 17:58:55 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 1,281 bytes | 
| コンパイル時間 | 2,934 ms | 
| コンパイル使用メモリ | 255,808 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-09-24 10:39:10 | 
| 合計ジャッジ時間 | 3,831 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 19 | 
ソースコード
#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;
}
            
            
            
        