結果

問題 No.1173 Endangered Species
ユーザー kimiyukikimiyuki
提出日時 2020-08-15 00:08:54
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 155 ms / 2,000 ms
コード長 1,663 bytes
コンパイル時間 2,111 ms
コンパイル使用メモリ 201,100 KB
実行使用メモリ 5,732 KB
最終ジャッジ日時 2023-08-01 00:20:10
合計ジャッジ時間 4,254 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 13 ms
4,380 KB
testcase_15 AC 9 ms
4,380 KB
testcase_16 AC 79 ms
4,380 KB
testcase_17 AC 125 ms
4,892 KB
testcase_18 AC 150 ms
5,052 KB
testcase_19 AC 155 ms
5,108 KB
testcase_20 AC 154 ms
5,732 KB
testcase_21 AC 153 ms
5,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "main.cpp"
#include <bits/stdc++.h>
#line 2 "/home/ubuntu/Library/utils/macros.hpp"
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) std::begin(x), std::end(x)
#line 4 "/home/ubuntu/Library/utils/binary_search_float.hpp"

/**
 * @brief a binary search on floating point numbers / 二分探索 (浮動小数点数)
 */
template <int Iteration = 64, typename UnaryPredicate>
double binsearch_float(double l, double r, UnaryPredicate p) {
    assert (l <= r);
    REP (i, Iteration) {
        double m = (l + r) / 2;
        (p(m) ? r : l) = m;
    }
    return r;
}
#line 4 "main.cpp"
using namespace std;

double solve(int n, const vector<double> & p, const vector<double> & q, const vector<int> & a) {
    auto f = [&](double r) -> double {
        double fr = 0;
        REP (i, n) {
            fr += p[i] * (1 - q[i]) / (1 - q[i] * r);
        }
        return fr;
    };
    double r = binsearch_float(0, 1, [&](double r) { return r >= f(r); });
    double ans = 0;
    REP (i, n) {
        double r_i = (1 - q[i]) / (1 - q[i] * r);
        ans += a[i] * log(r_i);
    }
    return ans;
}

int main() {
    int n; cin >> n;
    vector<double> p(n);
    REP (i, n) {
        cin >> p[i];
    }
    vector<double> q(n);
    REP (i, n) {
        cin >> q[i];
    }
    vector<int> a(n);
    REP (i, n) {
        cin >> a[i];
    }
    auto ans = solve(n, p, q, a);
    cout << setprecision(18) << ans << endl;
    return 0;
}
0