結果

問題 No.162 8020運動
ユーザー tottoripapertottoripaper
提出日時 2015-03-28 17:12:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 820 ms / 5,000 ms
コード長 1,305 bytes
コンパイル時間 442 ms
コンパイル使用メモリ 42,196 KB
実行使用メモリ 82,000 KB
最終ジャッジ日時 2023-09-11 10:49:32
合計ジャッジ時間 24,109 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 611 ms
79,528 KB
testcase_01 AC 710 ms
80,708 KB
testcase_02 AC 767 ms
81,304 KB
testcase_03 AC 816 ms
81,972 KB
testcase_04 AC 816 ms
81,920 KB
testcase_05 AC 817 ms
81,976 KB
testcase_06 AC 814 ms
81,956 KB
testcase_07 AC 812 ms
81,980 KB
testcase_08 AC 820 ms
82,000 KB
testcase_09 AC 611 ms
79,564 KB
testcase_10 AC 762 ms
81,300 KB
testcase_11 AC 707 ms
80,676 KB
testcase_12 AC 652 ms
80,052 KB
testcase_13 AC 819 ms
81,976 KB
testcase_14 AC 624 ms
79,552 KB
testcase_15 AC 621 ms
79,592 KB
testcase_16 AC 663 ms
80,144 KB
testcase_17 AC 631 ms
79,812 KB
testcase_18 AC 804 ms
81,840 KB
testcase_19 AC 755 ms
81,176 KB
testcase_20 AC 771 ms
81,496 KB
testcase_21 AC 772 ms
81,440 KB
testcase_22 AC 761 ms
81,336 KB
testcase_23 AC 771 ms
81,444 KB
testcase_24 AC 763 ms
81,344 KB
testcase_25 AC 786 ms
81,588 KB
testcase_26 AC 609 ms
79,524 KB
testcase_27 AC 721 ms
80,840 KB
testcase_28 AC 808 ms
81,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// Wrongri-La Shower

#include <cstdio>
#include <vector>

typedef std::pair<int,double> Pair;

double P[3]; // 虫歯に「なる」確率
std::vector<Pair> ns[1<<14];
double dp[21][1<<14];

double probability(int prev, int next){
    double res = 1.0;
    for(int i=0;i<14;i++){
        if(!(prev >> i & 1)){continue;}
        
        double p;
        if(i == 0){
            p = P[prev >> 1 & 1];
        }else if(i == 13){
            p = P[prev >> 12 & 1];
        }else{
            p = P[(prev >> i-1 & 1) + (prev >> i+1 & 1)];
        }

        res *= next >> i & 1 ? 1.0-p : p;
    }

    return res;
}

int main(){
    int N;
    scanf("%d", &N);
    N = 80-N;

    scanf("%lf %lf %lf", P, P+1, P+2);
    for(int i=0;i<3;i++){P[i] /= 100;}

    
    for(int i=0;i<1<<14;i++){
        for(int j=0;j<1<<14;j++){
            if((i & j) != j){continue;}

            ns[i].push_back(std::make_pair(j, probability(i, j)));
        }
    }

    dp[0][(1<<14)-1] = 1.0;
    for(int i=0;i<N;i++){
        for(int j=0;j<1<<14;j++){
            for(const auto& p : ns[j]){
                dp[i+1][p.first] += dp[i][j] * p.second;
            }
        }
    }

    double res = 0.0;
    for(int i=0;i<1<<14;i++){
        res += dp[N][i] * __builtin_popcount(i);
    }

    printf("%.12f\n", res * 2);
}
0