結果

問題 No.162 8020運動
ユーザー maine_honzukimaine_honzuki
提出日時 2020-06-01 16:37:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 647 ms / 5,000 ms
コード長 1,618 bytes
コンパイル時間 1,602 ms
コンパイル使用メモリ 168,080 KB
実行使用メモリ 42,276 KB
最終ジャッジ日時 2023-08-14 04:59:37
合計ジャッジ時間 20,106 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 448 ms
42,180 KB
testcase_01 AC 539 ms
42,220 KB
testcase_02 AC 593 ms
42,020 KB
testcase_03 AC 645 ms
42,180 KB
testcase_04 AC 646 ms
42,136 KB
testcase_05 AC 644 ms
42,220 KB
testcase_06 AC 643 ms
42,276 KB
testcase_07 AC 646 ms
42,020 KB
testcase_08 AC 647 ms
42,016 KB
testcase_09 AC 450 ms
42,160 KB
testcase_10 AC 594 ms
42,120 KB
testcase_11 AC 542 ms
42,116 KB
testcase_12 AC 490 ms
42,112 KB
testcase_13 AC 644 ms
42,192 KB
testcase_14 AC 461 ms
42,240 KB
testcase_15 AC 458 ms
42,216 KB
testcase_16 AC 502 ms
42,240 KB
testcase_17 AC 469 ms
42,124 KB
testcase_18 AC 635 ms
42,224 KB
testcase_19 AC 583 ms
42,060 KB
testcase_20 AC 602 ms
42,156 KB
testcase_21 AC 603 ms
42,072 KB
testcase_22 AC 595 ms
42,160 KB
testcase_23 AC 605 ms
42,112 KB
testcase_24 AC 592 ms
42,244 KB
testcase_25 AC 615 ms
42,224 KB
testcase_26 AC 450 ms
42,072 KB
testcase_27 AC 553 ms
42,120 KB
testcase_28 AC 635 ms
42,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

vector<double> memo[1 << 14];

int main() {
    int A, N;
    double P[3];
    cin >> A >> P[0] >> P[1] >> P[2];
    N = 80 - A;
    for (int i = 0; i < 3; i++) {
        P[i] /= 100;
    }

    double dp[2][1 << 14] = {};
    int now = 0, nxt = 1;
    dp[now][(1 << 14) - 1] = 1;


    auto prob = [&](int bit, int mask) {
        double ret = 1;
        for (int x = 0; x < 14; x++) {
            int cnt = 0;
            if (x != 0 && (bit & (1 << (x - 1))))
                cnt++;
            if (x != 13 && (bit & (1 << (x + 1))))
                cnt++;
            if (bit & (1 << x) && !(mask & (1 << x)))
                ret *= P[cnt];
            else if (bit & (1 << x) && (mask & (1 << x)))
                ret *= 1 - P[cnt];
        }
        return ret;
    };

    for (int bit = 0; bit < (1 << 14); bit++) {
        for (int mask = bit; mask >= 0; mask--) {
            mask &= bit;
            memo[bit].emplace_back(prob(bit, mask));
        }
    }


    while (N--) {
        for (int bit = 0; bit < (1 << 14); bit++) {
            dp[nxt][bit] = 0;
        }
        for (int bit = 0; bit < (1 << 14); bit++) {
            int cnt = 0;
            for (int mask = bit; mask >= 0; mask--) {
                mask &= bit;
                dp[nxt][mask] += dp[now][bit] * memo[bit][cnt];
                cnt++;
            }
        }
        swap(now, nxt);
    }

    double ans = 0;
    for (int bit = 0; bit < (1 << 14); bit++) {
        ans += dp[now][bit] * __builtin_popcount(bit);
    }

    cout << fixed << setprecision(10) << ans * 2 << endl;
}
0