結果

問題 No.1151 チャレンジゲーム
ユーザー tokusakuraitokusakurai
提出日時 2020-08-08 09:26:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 2,409 bytes
コンパイル時間 2,178 ms
コンパイル使用メモリ 204,600 KB
実行使用メモリ 10,096 KB
最終ジャッジ日時 2024-04-08 13:53:41
合計ジャッジ時間 6,519 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 3 ms
6,676 KB
testcase_13 AC 31 ms
6,912 KB
testcase_14 AC 24 ms
6,912 KB
testcase_15 AC 32 ms
6,912 KB
testcase_16 AC 25 ms
6,912 KB
testcase_17 AC 27 ms
6,912 KB
testcase_18 AC 30 ms
6,912 KB
testcase_19 AC 27 ms
6,912 KB
testcase_20 AC 28 ms
6,912 KB
testcase_21 AC 31 ms
6,912 KB
testcase_22 AC 23 ms
6,912 KB
testcase_23 AC 29 ms
6,912 KB
testcase_24 AC 30 ms
6,912 KB
testcase_25 AC 25 ms
6,912 KB
testcase_26 AC 27 ms
6,912 KB
testcase_27 AC 30 ms
6,912 KB
testcase_28 AC 59 ms
10,096 KB
testcase_29 AC 69 ms
10,096 KB
testcase_30 AC 73 ms
10,096 KB
testcase_31 AC 61 ms
10,096 KB
testcase_32 AC 64 ms
10,096 KB
testcase_33 AC 76 ms
10,096 KB
testcase_34 AC 72 ms
10,096 KB
testcase_35 AC 83 ms
10,096 KB
testcase_36 AC 85 ms
10,096 KB
testcase_37 AC 79 ms
10,096 KB
testcase_38 AC 55 ms
10,096 KB
testcase_39 AC 76 ms
10,096 KB
testcase_40 AC 62 ms
10,096 KB
testcase_41 AC 90 ms
10,096 KB
testcase_42 AC 83 ms
10,096 KB
testcase_43 AC 74 ms
10,096 KB
testcase_44 AC 46 ms
10,096 KB
testcase_45 AC 76 ms
10,096 KB
testcase_46 AC 77 ms
10,096 KB
testcase_47 AC 61 ms
10,096 KB
testcase_48 AC 13 ms
10,096 KB
testcase_49 AC 117 ms
10,096 KB
testcase_50 AC 40 ms
10,096 KB
testcase_51 AC 68 ms
10,096 KB
testcase_52 AC 68 ms
10,096 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:36:9: warning: '*sum[<unknown>]' may be used uninitialized [-Wmaybe-uninitialized]
   36 |     int all = sum[(1<<N)-1];
      |         ^~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N;
    cin >> N;
    int A[N];
    rep(i, N) cin >> A[i];
    int sum[1<<N];
    rep(i, 1<<N){
        sum[i] = 0;
        rep(j, N) if(i&(1<<j)) sum[i] += A[j];
    }
    int all = sum[(1<<N)-1];
    ld dp[1<<N][201][2];
    rep(i, 1<<N) rep(j, 201) rep(k, 2) dp[i][j][k] = 0.0;
    rep(j, 201){
        if(j*2 > all) rep(k, 2) dp[0][j][k] = 1.0;
    }
    rep(i, 1<<N){
        if(i == 0) continue;
        rep(j, all-sum[i]+1){
            ld memo1[N][N], memo2[N][N];
            fill(memo1[0], memo1[N], -1.0), fill(memo2[0], memo2[N], -1.0);
            rep(k, N) rep(l, N){
                if(!(i&(1<<k)) || !(i&(1<<l))) continue;
                ld s = 1.0/ld(A[k]), t = 1.0/ld(A[l]);
                ld p = dp[i^(1<<k)][j+A[k]][1], q = dp[i^(1<<l)][j][0];
                ld x = (s*p+(1-s)*t*q)/(s+t-s*t);
                ld y = t*q+(1-t)*x;
                memo1[k][l] = x, memo2[k][l] = y;
            }
            int res[N];
            rep(k, N){
                res[k] = -1;
                rep(l, N){
                    if(memo2[k][l] < -EPS) continue;
                    if(res[k] == -1) res[k] = l;
                    if(memo2[k][l] < memo2[k][res[k]]) res[k] = l;
                }
            }
            int a = -1;
            rep(k, N){
                if(res[k] == -1) continue;
                if(a == -1) a = k; 
                if(memo1[k][res[k]] > memo1[a][res[a]]) a = k;
            }
            dp[i][j][0] = memo1[a][res[a]], dp[i][j][1] = memo2[a][res[a]];
        }
    }
    cout << sp(10) << dp[(1<<N)-1][0][0] << endl;
}
0