結果

問題 No.66 輝け☆全国たこやき杯
ユーザー tottoripapertottoripaper
提出日時 2014-11-14 20:35:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,048 bytes
コンパイル時間 544 ms
コンパイル使用メモリ 52,052 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 03:40:41
合計ジャッジ時間 1,169 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)

int M;
double S[1024], dp[11][1024];
bool calculated[11][1024];

// indexがstageで勝つ確率(l, rはどこまでか)
double rec(int index, int stage, int l, int r){
    if(stage == M){return 1.0f;}
    if(calculated[stage][index]){return dp[stage][index];}

    int mid = (l+r) / 2;
    double res = 0.0f;
    if(l <= index && index < mid){
        FOR(i, mid, r){
            res += rec(i, stage+1, mid, r) * S[index] / (S[index] + S[i]);
        }
        res *= rec(index, stage+1, l, mid);
    }else{
        FOR(i, l, mid){
            res += rec(i, stage+1, l, mid) * S[index] / (S[index] + S[i]);
        }
        res *= rec(index, stage+1, mid, r);
    }

    calculated[stage][index] = true;
    return dp[stage][index] = res;
}

int main(){
    std::cin >> M;

    REP(i, 1<<M){
        std::cin >> S[i];
        S[i] *= S[i];
    }

    printf("%.8f\n", rec(0, 0, 0, 1<<M));
}
0