結果
問題 | No.1173 Endangered Species |
ユーザー |
|
提出日時 | 2020-08-15 00:08:54 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 186 ms / 2,000 ms |
コード長 | 1,663 bytes |
コンパイル時間 | 2,214 ms |
コンパイル使用メモリ | 195,664 KB |
最終ジャッジ日時 | 2025-01-13 00:49:02 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#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;}