結果

問題 No.1151 チャレンジゲーム
ユーザー mgingin142857mgingin142857
提出日時 2020-08-07 23:17:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 3,175 bytes
コンパイル時間 1,793 ms
コンパイル使用メモリ 173,164 KB
実行使用メモリ 4,496 KB
最終ジャッジ日時 2023-10-25 04:39:50
合計ジャッジ時間 5,788 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 25 ms
4,348 KB
testcase_14 AC 25 ms
4,348 KB
testcase_15 AC 26 ms
4,348 KB
testcase_16 AC 26 ms
4,348 KB
testcase_17 AC 25 ms
4,348 KB
testcase_18 AC 25 ms
4,348 KB
testcase_19 AC 25 ms
4,348 KB
testcase_20 AC 25 ms
4,348 KB
testcase_21 AC 26 ms
4,348 KB
testcase_22 AC 26 ms
4,348 KB
testcase_23 AC 26 ms
4,348 KB
testcase_24 AC 25 ms
4,348 KB
testcase_25 AC 25 ms
4,348 KB
testcase_26 AC 25 ms
4,348 KB
testcase_27 AC 25 ms
4,348 KB
testcase_28 AC 86 ms
4,496 KB
testcase_29 AC 82 ms
4,496 KB
testcase_30 AC 87 ms
4,496 KB
testcase_31 AC 75 ms
4,496 KB
testcase_32 AC 86 ms
4,496 KB
testcase_33 AC 86 ms
4,496 KB
testcase_34 AC 88 ms
4,496 KB
testcase_35 AC 89 ms
4,496 KB
testcase_36 AC 90 ms
4,496 KB
testcase_37 AC 88 ms
4,496 KB
testcase_38 AC 86 ms
4,496 KB
testcase_39 AC 90 ms
4,496 KB
testcase_40 AC 82 ms
4,496 KB
testcase_41 AC 87 ms
4,496 KB
testcase_42 AC 88 ms
4,496 KB
testcase_43 AC 89 ms
4,496 KB
testcase_44 AC 78 ms
4,496 KB
testcase_45 AC 84 ms
4,496 KB
testcase_46 AC 89 ms
4,496 KB
testcase_47 AC 83 ms
4,496 KB
testcase_48 AC 86 ms
4,496 KB
testcase_49 AC 83 ms
4,496 KB
testcase_50 AC 86 ms
4,496 KB
testcase_51 AC 90 ms
4,496 KB
testcase_52 AC 85 ms
4,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

int n;

VI makevec(int x) {
    VI v(n);
    for (int j = 0; j < n; j++) {
        if (x % 3 == 0)
            v[j] = 0;
        else if (x % 3 == 1)
            v[j] = 1;
        else
            v[j] = 2;
        x /= 3;
    }
    return v;
}

int rev(int x) {
    int j;
    int y = 0;
    int k = 1;
    for (j = 0; j < n; j++) {
        if (x % 3 == 1)
            y += k * 2;
        else if (x % 3 == 2)
            y += k;
        x /= 3;
        k *= 3;
    }
    return y;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j, k;
    cin >> n;
    int a[n];
    for (i = 0; i < n; i++) cin >> a[i];
    int all = 0;
    for (i = 0; i < n; i++) all += a[i];
    int m = pow(3, n);
    VI fl(m, -1);
    for (i = 0; i < m; i++) {
        VI v = makevec(i);
        int p = 0, q = 0;
        bool fin = 1;
        for (j = 0; j < n; j++) {
            if (v[j] == 1)
                p += a[j];
            else if (v[j] == 2)
                q += a[j];
            else
                fin = 0;
        }
        if (p > all - p)
            fl[i] = 1;
        else if (q >= all - q)
            fl[i] = 2;
    }

    double get[n];
    double iget[n];
    for (i = 0; i < n; i++) {
        get[i] = double(1.0) / a[i];
        iget[i] = 1.0 - get[i];
    }
    vector<double> dp(m, 0.0);

    for (i = m - 1; i >= 0; i--) {
        if (fl[i] == 1) {
            dp[i] = 1.0;
            //cout << i << " " << dp[i] << endl;
            continue;
        } else if (fl[i] == 2) {
            dp[i] = 0.0;
            // cout << i << " " << dp[i] << endl;
            continue;
        }
        VI v = makevec(i);
        for (j = 0; j < n; j++) {
            if (v[j] != 0) continue;
            // 取れた場合
            double w = 1.0;
            double w2 = 1.0;
            if (dp[i + pow(3, j)] < 0.00000001) w = 0.0;
            for (k = 0; k < n; k++) {
                if (j == k) continue;
                if (v[k] != 0) continue;
                chmin(w, get[k] * dp[i + pow(3, j) + 2 * pow(3, k)] + iget[k] * dp[i + pow(3, j)]);
            }
            // 取れない
            bool f = 0;
            for (k = 0; k < n; k++) {
                if (v[k] != 0) continue;
                f = 1;
                double cont = iget[j] * iget[k];
                chmin(w2, (get[j] * w + iget[j] * get[k] * dp[i + 2 * pow(3, k)]) / (1.0 - cont));
            }
            if (f) chmax(dp[i], w2);
        }
        //cout << i << " " << dp[i] << endl;
    }
    cout << fixed << setprecision(15) << dp[0] << endl;
}
0