結果

問題 No.1173 Endangered Species
ユーザー optopt
提出日時 2020-04-24 16:27:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 332 ms / 2,000 ms
コード長 847 bytes
コンパイル時間 2,736 ms
コンパイル使用メモリ 203,096 KB
実行使用メモリ 5,624 KB
最終ジャッジ日時 2023-09-19 07:23:31
合計ジャッジ時間 5,751 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 28 ms
4,376 KB
testcase_15 AC 19 ms
4,384 KB
testcase_16 AC 174 ms
4,652 KB
testcase_17 AC 273 ms
5,188 KB
testcase_18 AC 331 ms
5,624 KB
testcase_19 AC 332 ms
5,228 KB
testcase_20 AC 330 ms
5,176 KB
testcase_21 AC 329 ms
5,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 = double;
using V = vector<int>;
using Vld = vector<ld>;
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }

const ld EPS = 1e-9;


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;

  auto fun = [&] (ld z) {
    ld f = 0;
    rep(i, n) f += p[i] * exp(log_prob(q[i], z));
    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;
  }

  ld ans = 0;
  rep(i, n) ans += x[i] * log_prob(q[i], ok);
  cout << ans << endl;
  return 0;
}
0