結果
問題 | No.1173 Endangered Species |
ユーザー | jell |
提出日時 | 2020-08-14 23:18:40 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 93 ms / 2,000 ms |
コード長 | 16,748 bytes |
コンパイル時間 | 3,480 ms |
コンパイル使用メモリ | 223,544 KB |
実行使用メモリ | 8,320 KB |
最終ジャッジ日時 | 2024-11-14 23:22:32 |
合計ジャッジ時間 | 5,288 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 3 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 3 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 3 ms
5,248 KB |
testcase_13 | AC | 3 ms
5,248 KB |
testcase_14 | AC | 9 ms
5,248 KB |
testcase_15 | AC | 7 ms
5,248 KB |
testcase_16 | AC | 53 ms
6,272 KB |
testcase_17 | AC | 77 ms
7,680 KB |
testcase_18 | AC | 93 ms
8,320 KB |
testcase_19 | AC | 93 ms
8,320 KB |
testcase_20 | AC | 92 ms
8,192 KB |
testcase_21 | AC | 92 ms
8,320 KB |
ソースコード
#line 2 "Library/gcc_option.hpp" #ifdef LOCAL #define _GLIBCXX_DEBUG #else #pragma GCC optimize("O3") #pragma GCC target("avx,avx2") #pragma GCC optimize("unroll-loops") #endif #line 2 "codeforces-workspace/yu4.cpp" #include <bits/stdc++.h> // #include "extlib.hpp" #line 5 "Library/config.hpp" namespace config { const auto start_time{std::chrono::system_clock::now()}; int64_t elapsed() { using namespace std::chrono; const auto end_time{system_clock::now()}; return duration_cast<milliseconds>(end_time - start_time).count(); } __attribute__((constructor)) void setup() { using namespace std; ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); #ifdef _buffer_check atexit([]{ ofstream cnsl("CON"); char bufc; if(cin >> bufc) cnsl << "\n\033[1;35mwarning\033[0m: buffer not empty.\n\n"; }); #endif } unsigned cases(void), caseid = 1; template <class C> void main() { for(const unsigned total = cases(); caseid <= total; ++caseid) C(); } } // namespace config #line 3 "Library/utils/iostream_overload.hpp" namespace std { template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.first >> p.second; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.first << ' ' << p.second; } template <class tuple_t, size_t index> struct tupleis { static istream &apply(istream &is, tuple_t &t) { tupleis<tuple_t, index - 1>::apply(is, t); return is >> get<index>(t); } }; template <class tuple_t> struct tupleis<tuple_t, SIZE_MAX> { static istream &apply(istream &is, tuple_t &t) { return is; } }; template <class... T> istream &operator>>(istream &is, tuple<T...> &t) { return tupleis<tuple<T...>, tuple_size<tuple<T...>>::value - 1>::apply(is, t); } template <> istream &operator>>(istream &is, tuple<> &t) { return is; } template <class tuple_t, size_t index> struct tupleos { static ostream &apply(ostream &os, const tuple_t &t) { tupleos<tuple_t, index - 1>::apply(os, t); return os << ' ' << get<index>(t); } }; template <class tuple_t> struct tupleos<tuple_t, 0> { static ostream &apply(ostream &os, const tuple_t &t) { return os << get<0>(t); } }; template <class... T> ostream &operator<<(ostream &os, const tuple<T...> &t) { return tupleos<tuple<T...>, tuple_size<tuple<T...>>::value - 1>::apply(os, t); } template <> ostream &operator<<(ostream &os, const tuple<> &t) { return os; } template <class Container, typename Value = typename Container::value_type, enable_if_t<!is_same<decay_t<Container>, string>::value, nullptr_t> = nullptr> istream& operator>>(istream& is, Container &cont) { for(auto&& e : cont) is >> e; return is; } template <class Container, typename Value = typename Container::value_type, enable_if_t<!is_same<decay_t<Container>, string>::value, nullptr_t> = nullptr> ostream& operator<<(ostream& os, const Container &cont) { bool flag = 1; for(auto&& e : cont) flag ? flag = 0 : (os << ' ', 0), os << e; return os; } } // namespace std #line 3 "Library/utils/read.hpp" namespace workspace { // read with std::cin. template <class T = void> struct read { typename std::remove_const<T>::type value; template <class... types> read(types... args) : value(args...) { std::cin >> value; } operator T() const { return value; } }; template <> struct read<void> { template <class T> operator T() const { T value; std::cin >> value; return value; } }; } // namespace workspace #line 3 "Library/utils/casefmt.hpp" namespace workspace { std::ostream &casefmt(std::ostream& os) { return os << "Case #" << config::caseid << ": "; } } // namespace workspace #line 3 "Library/utils/fixed_point.hpp" namespace workspace { // specify the return type of lambda. template <class lambda_type> class fixed_point { lambda_type func; public: fixed_point(lambda_type &&f) : func(std::move(f)) {} template <class... Args> auto operator()(Args &&... args) const { return func(*this, std::forward<Args>(args)...); } }; } // namespace workspace #line 3 "Library/utils/chval.hpp" namespace workspace { template <class T, class Comp = std::less<T>> bool chle(T &x, const T &y, Comp comp = Comp()) { return comp(y, x) ? x = y, true : false; } template <class T, class Comp = std::less<T>> bool chge(T &x, const T &y, Comp comp = Comp()) { return comp(x, y) ? x = y, true : false; } } // namespace workspace #line 5 "Library/utils/binary_search.hpp" namespace workspace { // binary search on discrete range. template <class iter_type, class pred_type, std::enable_if_t<std::is_convertible_v<std::invoke_result_t<pred_type, iter_type>, bool>, std::nullptr_t> = nullptr> iter_type binary_search(iter_type ok, iter_type ng, pred_type pred) { assert(ok != ng); intmax_t dist(ng - ok); while(std::abs(dist) > 1) { iter_type mid(ok + dist / 2); if(pred(mid)) ok = mid, dist -= dist / 2; else ng = mid, dist /= 2; } return ok; } // binary search on real numbers. template <class real_type, class pred_type, std::enable_if_t<std::is_convertible_v<std::invoke_result_t<pred_type, real_type>, bool>, std::nullptr_t> = nullptr> real_type binary_search(real_type ok, real_type ng, const real_type eps, pred_type pred) { assert(ok != ng); while(std::abs(ok - ng) > eps) { real_type mid{(ok + ng) / 2}; (pred(mid) ? ok : ng) = mid; } return ok; } } // namespace workspace #line 2 "Library/alias.hpp" using namespace std; using namespace __gnu_cxx; using i32 = int_least32_t; using i64 = int_least64_t; using p32 = pair<i32, i32>; using p64 = pair<i64, i64>; template <class T, class Comp = less<T>> using heap = priority_queue<T, vector<T>, Comp>; template <class T> using hashset = unordered_set<T>; template <class Key, class Value> using hashmap = unordered_map<Key, Value>; #line 12 "codeforces-workspace/yu4.cpp" namespace workspace { struct solver; } int main() { config::main<workspace::solver>(); } unsigned config::cases() { // return -1; // not specify // return read(); // given return 1; } #line 1 "Library/data_structure/union_find/union_find.hpp" #line 6 "Library/data_structure/union_find/union_find.hpp" class union_find { std::vector<int> link; public: explicit union_find(const unsigned n = 0) : link(n, -1) {} unsigned find(unsigned x) { assert(x < size()); return link[x] < 0 ? x : (link[x] = find(link[x])); } unsigned size() const { return link.size(); } unsigned size(const unsigned x) { assert(x < size()); return -link[find(x)]; } bool same(const unsigned x, const unsigned y) { assert(x < size() && y < size()); return find(x) == find(y); } bool unite(unsigned x, unsigned y) { assert(x < size() && y < size()); x = find(x), y = find(y); if(x == y) return false; if(link[x] > link[y]) std::swap(x, y); link[x] += link[y]; link[y] = x; return true; } }; // class union_find #line 4 "Library/modulus/modint.hpp" template <int_fast64_t mod = 0> // compile-time defined modulo. struct modint { static_assert(mod > 0); template <bool i32, class = void> struct modif { using value_type = int_least32_t; }; template <class void_t> struct modif<false, void_t> { using value_type = int_least64_t; }; using value_type = typename modif<mod < (1 << 30)>::value_type; constexpr static modint one() noexcept { return 1; } constexpr operator value_type() const noexcept { return value; } constexpr modint() noexcept = default; template <class int_type, std::enable_if_t<std::is_integral<int_type>::value, std::nullptr_t> = nullptr> constexpr modint(int_type n) noexcept : value((n %= mod) < 0 ? mod + n : n) {} constexpr modint operator++(int) noexcept { modint t{*this}; return operator+=(1), t; } constexpr modint operator--(int) noexcept { modint t{*this}; return operator-=(1), t; } constexpr modint &operator++() noexcept { return operator+=(1); } constexpr modint &operator--() noexcept { return operator-=(1); } constexpr modint operator-() const noexcept { return value ? mod - value : 0; } constexpr modint &operator+=(const modint &rhs) noexcept { return (value += rhs.value) < mod ? 0 : value -= mod, *this; } constexpr modint &operator-=(const modint &rhs) noexcept { return (value += mod - rhs.value) < mod ? 0 : value -= mod, *this; } constexpr modint &operator*=(const modint &rhs) noexcept { return value = (int_fast64_t)value * rhs.value % mod, *this; } constexpr modint &operator/=(const modint &rhs) noexcept { return operator*=(rhs.inverse()); } template <class int_type, std::enable_if_t<std::is_integral<int_type>::value, std::nullptr_t> = nullptr> constexpr modint operator+(const int_type &rhs) const noexcept { return modint{*this} += rhs; } constexpr modint operator+(const modint &rhs) const noexcept { return modint{*this} += rhs; } template <class int_type, std::enable_if_t<std::is_integral<int_type>::value, std::nullptr_t> = nullptr> constexpr modint operator-(const int_type &rhs) const noexcept { return modint{*this} -= rhs; } constexpr modint operator-(const modint &rhs) const noexcept { return modint{*this} -= rhs; } template <class int_type, std::enable_if_t<std::is_integral<int_type>::value, std::nullptr_t> = nullptr> constexpr modint operator*(const int_type &rhs) const noexcept { return modint{*this} *= rhs; } constexpr modint operator*(const modint &rhs) const noexcept { return modint{*this} *= rhs; } template <class int_type, std::enable_if_t<std::is_integral<int_type>::value, std::nullptr_t> = nullptr> constexpr modint operator/(const int_type &rhs) const noexcept { return modint{*this} /= rhs; } constexpr modint operator/(const modint &rhs) const noexcept { return modint{*this} /= rhs; } template <class int_type, std::enable_if_t<std::is_integral<int_type>::value, std::nullptr_t> = nullptr> constexpr friend modint operator+(const int_type &lhs, const modint &rhs) noexcept { return modint(lhs) + rhs; } template <class int_type, std::enable_if_t<std::is_integral<int_type>::value, std::nullptr_t> = nullptr> constexpr friend modint operator-(const int_type &lhs, const modint &rhs) noexcept { return modint(lhs) - rhs; } template <class int_type, std::enable_if_t<std::is_integral<int_type>::value, std::nullptr_t> = nullptr> constexpr friend modint operator*(const int_type &lhs, const modint &rhs) noexcept { return modint(lhs) * rhs; } template <class int_type, std::enable_if_t<std::is_integral<int_type>::value, std::nullptr_t> = nullptr> constexpr friend modint operator/(const int_type &lhs, const modint &rhs) noexcept { return modint(lhs) / rhs; } constexpr modint inverse() const noexcept { assert(value); value_type a{mod}, b{value}, u{}, v{1}, t{}; while(b) t = a / b, a ^= b ^= (a -= t * b) ^= b, u ^= v ^= (u -= t * v) ^= v; return {u}; } constexpr static modint pow(modint rhs, int_fast64_t e) noexcept { if(e < 0) e = e % (mod - 1) + mod - 1; modint res{1}; while(e) { if(e & 1) res *= rhs; rhs *= rhs, e >>= 1; } return res; } friend std::ostream &operator<<(std::ostream &os, const modint &rhs) noexcept { return os << rhs.value; } friend std::istream &operator>>(std::istream &is, modint &rhs) noexcept { value_type value; rhs = (is >> value, value); return is; } protected: value_type value = 0; }; // class modint template <> // runtime defined modulo as default(mod = 0). struct modint<0> { using value_type = int_fast64_t; static value_type &mod() noexcept { static value_type mod{}; return mod; } static modint one() noexcept { return 1; } operator value_type() const noexcept { return value; } modint() noexcept = default; template <class int_type, std::enable_if_t<std::is_integral<int_type>::value, std::nullptr_t> = nullptr> modint(int_type n) noexcept : value{ (assert(mod()), n %= mod()) < 0 ? n + mod() : n} {} modint operator++(int) noexcept { modint t{*this}; return operator+=(1), t; } modint operator--(int) noexcept { modint t{*this}; return operator-=(1), t; } modint &operator++() noexcept { return operator+=(1); } modint &operator--() noexcept { return operator-=(1); } modint operator-() const noexcept { return value ? mod() - value : 0; } modint &operator+=(const modint &rhs) noexcept { return (value += rhs.value) < mod() ? 0 : value -= mod(), *this; } modint &operator-=(const modint &rhs) noexcept { return (value += mod() - rhs.value) < mod() ? 0 : value -= mod(), *this; } modint &operator*=(const modint &rhs) noexcept { return (value *= rhs.value) %= mod(), *this; } modint &operator/=(const modint &rhs) noexcept { return operator*=(rhs.inverse()); } template <class int_type, std::enable_if_t<std::is_integral<int_type>::value, std::nullptr_t> = nullptr> modint operator+(const int_type &rhs) const noexcept { return modint{*this} += rhs; } modint operator+(const modint &rhs) const noexcept { return modint{*this} += rhs; } template <class int_type, std::enable_if_t<std::is_integral<int_type>::value, std::nullptr_t> = nullptr> modint operator-(const int_type &rhs) const noexcept { return modint{*this} -= rhs; } modint operator-(const modint &rhs) const noexcept { return modint{*this} -= rhs; } template <class int_type, std::enable_if_t<std::is_integral<int_type>::value, std::nullptr_t> = nullptr> modint operator*(const int_type &rhs) const noexcept { return modint{*this} *= rhs; } modint operator*(const modint &rhs) const noexcept { return modint{*this} *= rhs; } template <class int_type, std::enable_if_t<std::is_integral<int_type>::value, std::nullptr_t> = nullptr> modint operator/(const int_type &rhs) const noexcept { return modint{*this} /= rhs; } modint operator/(const modint &rhs) const noexcept { return modint{*this} /= rhs; } template <class int_type, std::enable_if_t<std::is_integral<int_type>::value, std::nullptr_t> = nullptr> friend modint operator+(const int_type &lhs, const modint &rhs) noexcept { return modint(lhs) + rhs; } template <class int_type, std::enable_if_t<std::is_integral<int_type>::value, std::nullptr_t> = nullptr> friend modint operator-(const int_type &lhs, const modint &rhs) noexcept { return modint(lhs) - rhs; } template <class int_type, std::enable_if_t<std::is_integral<int_type>::value, std::nullptr_t> = nullptr> friend modint operator*(const int_type &lhs, const modint &rhs) noexcept { return modint(lhs) * rhs; } template <class int_type, std::enable_if_t<std::is_integral<int_type>::value, std::nullptr_t> = nullptr> friend modint operator/(const int_type &lhs, const modint &rhs) noexcept { return modint(lhs) / rhs; } modint inverse() const noexcept { assert(mod() && value); long long a{mod()}, b{value}, u{}, v{1}, t{}; while(b) t = a / b, a ^= b ^= (a -= t * b) ^= b, u ^= v ^= (u -= t * v) ^= v; return {u}; } static modint pow(modint rhs, int_fast64_t e) noexcept { if(e < 0) e = e % (mod() - 1) + mod() - 1; modint res{1}; while(e) { if(e & 1) res *= rhs; rhs *= rhs, e >>= 1; } return res; } friend std::ostream &operator<<(std::ostream &os, const modint &rhs) noexcept { return os << rhs.value; } friend std::istream &operator>>(std::istream &is, modint &rhs) noexcept { long long value; rhs = modint((is >> value, value)); return is; } protected: value_type value = 0; }; // class modint<0> using modint_runtime = modint<0>; #line 21 "codeforces-workspace/yu4.cpp" struct workspace::solver { // start here! using mint=modint<(int)1e9+7>; solver() { int n; cin>>n; vector<long double> p(n),q(n); cin>>p>>q; auto f=[&](long double u)->double { long double ret=0; for(int i=0;i<n;i++) { ret+=p[i]*(1-q[i])/(1-q[i]*u); } return ret; }; long double ok=0.0; long double ng=1; const long double eps=1e-10; auto pred=[&](long double x)->bool { return f(x)>x; }; long double u=binary_search(ok,ng,eps,pred); vector<long double> ul(n); long double ans=0; for(int i=0;i<n;i++) { long double ui=(1-q[i])/(1-q[i]*u); ul[i]=ui; int a; cin>>a; ans+=a*log(ui); } cout<<ans<<endl; }};