結果

問題 No.162 8020運動
ユーザー tktk_snsntktk_snsn
提出日時 2021-03-18 00:36:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 693 ms / 5,000 ms
コード長 1,490 bytes
コンパイル時間 1,580 ms
コンパイル使用メモリ 171,448 KB
実行使用メモリ 82,736 KB
最終ジャッジ日時 2023-08-09 21:05:02
合計ジャッジ時間 21,105 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 477 ms
79,976 KB
testcase_01 AC 585 ms
81,208 KB
testcase_02 AC 635 ms
82,020 KB
testcase_03 AC 678 ms
82,544 KB
testcase_04 AC 685 ms
82,736 KB
testcase_05 AC 693 ms
82,484 KB
testcase_06 AC 692 ms
82,636 KB
testcase_07 AC 686 ms
82,532 KB
testcase_08 AC 670 ms
82,480 KB
testcase_09 AC 463 ms
80,228 KB
testcase_10 AC 609 ms
82,076 KB
testcase_11 AC 599 ms
81,384 KB
testcase_12 AC 520 ms
80,688 KB
testcase_13 AC 686 ms
82,524 KB
testcase_14 AC 475 ms
80,152 KB
testcase_15 AC 477 ms
80,160 KB
testcase_16 AC 518 ms
80,724 KB
testcase_17 AC 488 ms
80,416 KB
testcase_18 AC 663 ms
82,456 KB
testcase_19 AC 618 ms
81,700 KB
testcase_20 AC 635 ms
82,156 KB
testcase_21 AC 628 ms
81,996 KB
testcase_22 AC 635 ms
82,080 KB
testcase_23 AC 643 ms
81,944 KB
testcase_24 AC 618 ms
82,076 KB
testcase_25 AC 658 ms
82,412 KB
testcase_26 AC 467 ms
80,028 KB
testcase_27 AC 578 ms
81,356 KB
testcase_28 AC 676 ms
82,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int U = 14;
double dp[30][1<<15];

double calc(int& s, int& t, double& x, double& y, double& z) {
    double res = 1.0;
    for (int i=0; i<U; ++i){
        if ((s>>i)&1) {
            int cnt = 0;
            if (i && (s>>(i-1)&1)) cnt++;
            if (i+1<U && (s>>(i+1)&1)) cnt++;
            if (cnt==0) {
                if ((t>>i)&1) res *= 1.0-x;
                else res *= x;
            }
            else if (cnt == 1) {
                if ((t>>i)&1) res *= 1.0-y;
                else res *= y;
            }
            else {
                if ((t>>i)&1) res *= 1.0-z;
                else res *= z;
            }
        }
    }
    return res;
}


int main() {
    int n; cin >> n;
    n = 80 - n;
    double x, y, z; cin >> x >> y >> z;
    x /= 100.0;
    y /= 100.0;
    z /= 100.0;
    vector<vector<pair<int,double>>> p(1<<U);
    for (int s=0; s < (1<<U); s++) {
        int t = s;
        while (true) {
            p[s].push_back(make_pair(t, calc(s,t,x,y,z)));
            t = (t-1)&s;
            if (s == t) break;
        }
    }
    dp[0][(1<<U)-1] = 1.0;
    for (int i=0; i<n; ++i) {
        for (int s=0; s<(1<<U);++s){
            for (auto x: p[s]) {
                dp[i+1][x.first] += dp[i][s] * x.second;
            }
        }
    }
    double ans = 0.0;
    for (int s=0; s<(1<<U); ++s){
        ans += __builtin_popcount(s) * dp[n][s];
    }
    printf("%.12f\n", 2*ans);
}
0