結果

問題 No.1151 チャレンジゲーム
ユーザー betrue12betrue12
提出日時 2020-08-10 13:17:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,503 bytes
コンパイル時間 2,359 ms
コンパイル使用メモリ 199,752 KB
実行使用メモリ 13,952 KB
最終ジャッジ日時 2024-04-16 11:09:16
合計ジャッジ時間 5,068 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 9 ms
7,424 KB
testcase_14 AC 9 ms
7,296 KB
testcase_15 AC 9 ms
7,424 KB
testcase_16 AC 9 ms
7,296 KB
testcase_17 AC 8 ms
7,168 KB
testcase_18 AC 9 ms
7,168 KB
testcase_19 AC 9 ms
7,296 KB
testcase_20 AC 8 ms
7,424 KB
testcase_21 AC 9 ms
7,296 KB
testcase_22 AC 9 ms
7,296 KB
testcase_23 AC 8 ms
7,168 KB
testcase_24 AC 9 ms
7,168 KB
testcase_25 AC 9 ms
7,296 KB
testcase_26 AC 9 ms
7,168 KB
testcase_27 AC 9 ms
7,168 KB
testcase_28 AC 23 ms
13,824 KB
testcase_29 AC 23 ms
13,824 KB
testcase_30 AC 23 ms
13,824 KB
testcase_31 AC 23 ms
13,696 KB
testcase_32 AC 23 ms
13,568 KB
testcase_33 AC 24 ms
13,696 KB
testcase_34 AC 23 ms
13,824 KB
testcase_35 AC 22 ms
13,696 KB
testcase_36 AC 24 ms
13,696 KB
testcase_37 AC 23 ms
13,696 KB
testcase_38 AC 24 ms
13,696 KB
testcase_39 AC 23 ms
13,696 KB
testcase_40 AC 23 ms
13,696 KB
testcase_41 AC 22 ms
13,696 KB
testcase_42 AC 23 ms
13,952 KB
testcase_43 AC 23 ms
13,696 KB
testcase_44 AC 24 ms
13,952 KB
testcase_45 AC 23 ms
13,696 KB
testcase_46 AC 23 ms
13,824 KB
testcase_47 AC 24 ms
13,696 KB
testcase_48 AC 24 ms
13,824 KB
testcase_49 AC 23 ms
13,824 KB
testcase_50 AC 23 ms
13,696 KB
testcase_51 AC 23 ms
13,824 KB
testcase_52 AC 24 ms
13,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

void chmax(double& a, double b){
    a = max(a, b);
}
void chmin(double& a, double b){
    a = min(a, b);
}

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

int main(){
    int N;
    cin >> N;
    vector<double> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    int B = 1<<N;
    static double dp[1024][1024][2];
    for(int s0=0; s0<B; s0++){
        int sum0 = 0, sum1 = 0;
        for(int i=0; i<N; i++) (nth_bit(s0, i) ? sum0 : sum1) += A[i];
        for(int k=0; k<2; k++) dp[s0][B-1-s0][k] = (sum0 > sum1);
    }

    for(int s0=B-1; s0>=0; s0--) for(int s1=B-1; s1>=0; s1--) if((s0&s1) == 0 && (s0|s1) != B-1){
        vector<int> yet;
        for(int i=0; i<N; i++) if(nth_bit(s0|s1, i) == 0) yet.push_back(i);
        
        dp[s0][s1][0] = 0;
        for(int i : yet){
            double tmp = 1;
            for(int j : yet){
                double res = (A[j]*dp[s0|(1<<i)][s1][1] + (A[i]-1)*dp[s0][s1|(1<<j)][0]) / (A[i]+A[j]-1);
                chmin(tmp, res);
            }
            chmax(dp[s0][s1][0], tmp);
        }

        dp[s0][s1][1] = 1;
        for(int j : yet){
            double tmp = 0;
            for(int i : yet){
                double res = ((A[j]-1)*dp[s0|(1<<i)][s1][1] + A[i]*dp[s0][s1|(1<<j)][0]) / (A[i]+A[j]-1);
                chmax(tmp, res);
            }
            chmin(dp[s0][s1][1], tmp);
        }
    }
    cout << fixed << setprecision(10) << dp[0][0][0] << endl;
    return 0;
}
0