結果

問題 No.162 8020運動
ユーザー tktk_snsntktk_snsn
提出日時 2021-03-18 00:36:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 631 ms / 5,000 ms
コード長 1,490 bytes
コンパイル時間 1,705 ms
コンパイル使用メモリ 171,984 KB
実行使用メモリ 83,072 KB
最終ジャッジ日時 2024-04-27 15:34:08
合計ジャッジ時間 18,640 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 418 ms
80,128 KB
testcase_01 AC 512 ms
81,408 KB
testcase_02 AC 574 ms
82,176 KB
testcase_03 AC 621 ms
83,072 KB
testcase_04 AC 627 ms
82,816 KB
testcase_05 AC 631 ms
82,688 KB
testcase_06 AC 615 ms
82,944 KB
testcase_07 AC 630 ms
82,816 KB
testcase_08 AC 616 ms
82,816 KB
testcase_09 AC 425 ms
80,384 KB
testcase_10 AC 576 ms
82,176 KB
testcase_11 AC 513 ms
81,408 KB
testcase_12 AC 463 ms
80,896 KB
testcase_13 AC 623 ms
82,944 KB
testcase_14 AC 431 ms
80,256 KB
testcase_15 AC 433 ms
80,384 KB
testcase_16 AC 470 ms
81,152 KB
testcase_17 AC 438 ms
80,512 KB
testcase_18 AC 616 ms
82,816 KB
testcase_19 AC 554 ms
82,048 KB
testcase_20 AC 579 ms
82,304 KB
testcase_21 AC 579 ms
82,304 KB
testcase_22 AC 572 ms
82,304 KB
testcase_23 AC 585 ms
82,304 KB
testcase_24 AC 565 ms
82,304 KB
testcase_25 AC 591 ms
82,560 KB
testcase_26 AC 414 ms
80,256 KB
testcase_27 AC 532 ms
81,536 KB
testcase_28 AC 605 ms
82,560 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