結果

問題 No.210 探し物はどこですか?
ユーザー tottoripaper
提出日時 2019-03-09 09:55:55
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 1,129 bytes
コンパイル時間 1,601 ms
コンパイル使用メモリ 178,744 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2024-06-23 15:11:20
合計ジャッジ時間 8,406 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<double,int>;

int N;
double p[1000], q[1000], alpha = 1.0;
std::priority_queue<P> pq;
std::stack<double> st;

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

    std::cin >> N;

    for(int i=0;i<N;++i){
        std::cin >> p[i];
        p[i] *= 1e-3;
    }

    for(int i=0;i<N;++i){
        std::cin >> q[i];
        q[i] *= 1e-2;
    }

    for(int i=0;i<N;++i){
        pq.emplace(p[i] * q[i], i);
    }

    for(int t=0;t<1'000'000;++t){
        double r;
        int i;
        std::tie(r, i) = pq.top();
        pq.pop();

        double s = r / alpha;

        st.emplace(s);

        if(s == 1){
            break;
        }

        alpha *= 1.0 - s;
        pq.emplace(r * (1.0 - q[i]), i);   
    }

    double e = 0;
    until(st.empty()){
        double s = st.top();
        st.pop();
        
        e = 1.0 + (1.0 - s) * e;
    }
    
    printf("%.5f\n", e);
}
0