結果
問題 |
No.1173 Endangered Species
|
ユーザー |
![]() |
提出日時 | 2020-04-24 04:02:13 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,517 bytes |
コンパイル時間 | 2,578 ms |
コンパイル使用メモリ | 198,496 KB |
最終ジャッジ日時 | 2025-01-09 22:57:05 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 RE * 1 |
other | AC * 11 RE * 8 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep2(i, m, n) for(int i=int(m); i<int(n); ++i) #define rep(i, n) rep2(i, 0, n) using ll = long long; using ld = long double; using V = vector<int>; using Vld = vector<ld>; // struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; } template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; } const ld EPS = 1e-13; ld log_prob(ld a, ld z) { return log(1-a) - log(1-a*z); } int main() { ll n; cin >> n; Vld p(n), q(n); cin >> p >> q; V x(n); cin >> x; assert(n >= 1 && n <= 1000); ld sum = 0; rep(i, n) { assert(p[i] + EPS >= 0 && p[i] - EPS <= 1); sum += p[i]; assert(q[i] + EPS >= 1e-5 && q[i] - EPS <= 1); assert(x[i] >= 0 && x[i] <= 1000); } assert(sum - EPS <= 1 && sum + EPS >= 1); auto fun = [&] (ld z) { ld f = 0; rep(i, n) f += p[i] * exp(log_prob(q[i], z)); // rep(i, n) f += p[i] * (1-q[i]) / (1-q[i]*z); // cout << z << " " << f << endl; return (z < f); }; ld ok = 0; ld ng = 1; while (abs(ok - ng) > EPS) { ld md = (ok + ng) / 2; if (fun(md)) ok = md; else ng = md; // cout << md << endl; } ld ans = 0; rep(i, n) ans += x[i] * log_prob(q[i], ok); cout << ans << endl; // cout << exp(ans) << endl; return 0; }