結果

問題 No.66 輝け☆全国たこやき杯
ユーザー GOTKAKO
提出日時 2025-06-29 22:24:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 931 bytes
コンパイル時間 2,087 ms
コンパイル使用メモリ 202,052 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2025-06-29 22:24:28
合計ジャッジ時間 2,674 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int M; cin >> M;
    int m2 = 1<<M;
    vector<int> S(m2);
    for(auto &s : S) cin >> s,s = s*s;

    vector<vector<double>> P(m2,vector<double>(m2));
    for(int i=0; i<m2; i++) for(int k=i+1; k<m2; k++){
        double p = S.at(i)/(S.at(i)+S.at(k)+0.0);
        P.at(i).at(k) = p,P.at(k).at(i) = 1-p;
    }
    
    vector<double> W(m2,1);
    for(int d=0; d<M; d++){
        vector<double> next(m2);
        for(int i=0; i<m2; i+=(2<<d)){
            int i2 = i+(1<<d),i3 = i2+(1<<d);
            for(int p=i; p<i2; p++) for(int q=i2; q<i3; q++){
                double all = W.at(p)*W.at(q);
                next.at(p) += all*P.at(p).at(q);
                next.at(q) += all*P.at(q).at(p);
            }
        }
        swap(W,next);
    }

    cout << fixed << setprecision(20) << W.at(0) << endl;
}
0