結果

問題 No.162 8020運動
ユーザー maine_honzukimaine_honzuki
提出日時 2020-06-01 16:37:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 653 ms / 5,000 ms
コード長 1,618 bytes
コンパイル時間 1,602 ms
コンパイル使用メモリ 171,944 KB
実行使用メモリ 42,496 KB
最終ジャッジ日時 2024-05-01 17:44:26
合計ジャッジ時間 18,653 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 438 ms
42,240 KB
testcase_01 AC 507 ms
42,368 KB
testcase_02 AC 548 ms
42,368 KB
testcase_03 AC 592 ms
42,368 KB
testcase_04 AC 593 ms
42,368 KB
testcase_05 AC 596 ms
42,368 KB
testcase_06 AC 596 ms
42,368 KB
testcase_07 AC 592 ms
42,368 KB
testcase_08 AC 594 ms
42,240 KB
testcase_09 AC 440 ms
42,368 KB
testcase_10 AC 553 ms
42,368 KB
testcase_11 AC 510 ms
42,368 KB
testcase_12 AC 470 ms
42,368 KB
testcase_13 AC 586 ms
42,496 KB
testcase_14 AC 443 ms
42,368 KB
testcase_15 AC 445 ms
42,368 KB
testcase_16 AC 477 ms
42,368 KB
testcase_17 AC 453 ms
42,240 KB
testcase_18 AC 653 ms
42,368 KB
testcase_19 AC 585 ms
42,368 KB
testcase_20 AC 558 ms
42,240 KB
testcase_21 AC 560 ms
42,368 KB
testcase_22 AC 548 ms
42,368 KB
testcase_23 AC 558 ms
42,368 KB
testcase_24 AC 547 ms
42,368 KB
testcase_25 AC 565 ms
42,368 KB
testcase_26 AC 438 ms
42,368 KB
testcase_27 AC 518 ms
42,368 KB
testcase_28 AC 580 ms
42,368 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