結果
問題 | No.1151 チャレンジゲーム |
ユーザー |
![]() |
提出日時 | 2020-08-08 00:51:55 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 67 ms / 2,000 ms |
コード長 | 3,837 bytes |
コンパイル時間 | 3,177 ms |
コンパイル使用メモリ | 202,760 KB |
最終ジャッジ日時 | 2025-01-12 18:41:44 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;using ld = long double;using V = vector<int>;using Vll = vector<ll>;using Vld = vector<ld>;using Vbo = vector<bool>;using VV = vector<V>;using VVll = vector<Vll>;using VVld = vector<Vld>;using VVbo = vector<Vbo>;using VVV = vector<VV>;using VVVll = vector<VVll>;using VVVld = vector<VVld>;using P = pair<int, int>;using Pll = pair<ll, ll>;using Pld = pair<ld, ld>;#define rep2(i, m, n) for (int i = (m); i < (n); ++i)#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)#define rep(i, n) rep2(i, 0, n)#define drep(i, n) drep2(i, n, 0)#define all(a) (a).begin(), (a).end()struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;template<typename T> inline int sz(T &x) { return x.size(); }template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; returnos; }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; }template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)inline int fLog2(const int x) { assert(x > 0); return 31-__builtin_clz(x); } // floor(log2(x))inline int fLog2(const ll x) { assert(x > 0); return 63-__builtin_clzll(x); }inline int cLog2(const int x) { assert(x > 0); return (x == 1) ? 0 : 32-__builtin_clz(x-1); } // ceil(log2(x))inline int cLog2(const ll x) { assert(x > 0); return (x == 1) ? 0 : 64-__builtin_clzll(x-1); }inline int popcount(const int x) { return __builtin_popcount(x); }inline int popcount(const ll x) { return __builtin_popcountll(x); }void fail() { puts("-1"); exit(0); }// const int INF = 1<<30;// const ll INFll = 1ll<<62;// const ld EPS = 1e-10;// const ld PI = acos(-1.0);// const int MOD = int(1e9)+7;// const int MOD = 998244353;V convert(ll x, int b, int n) {V res;for (int i = 0; i < n; ++i) {res.push_back(x%b);x /= b;}return res;}int main() {int n; cin >> n;V a(n); cin >> a;Vld b(n);rep(i, n) b[i] = ld(1) / a[i];int N = 1;rep(i, n) N *= 3;VVld p(2, Vld(N, -1));rep(S, N) {V v = convert(S, 3, n);bool ini = true;rep(i, n) if (v[i] == 0) ini = false;if (!ini) {p[0][S] = 0;p[1][S] = 1;continue;}V s(2);rep(i, n) s[v[i]-1] += a[i];if (s[0] <= s[1]) p[0][S] = 0, p[1][S] = 0;else p[0][S] = 1, p[1][S] = 1;}V pw3(n);pw3[0] = 1;rep(i, n-1) pw3[i+1] = pw3[i] * 3;drep(S, N) {V v = convert(S, 3, n);rep(i, n) if (v[i] == 0) {ld cmin = 1;rep(j, n) if (v[j] == 0) {int x = S + pw3[i];int y = S + pw3[j] * 2;ld now = p[1][x] * b[i] + p[0][y] * (1-b[i]) * b[j];now /= 1 - (1-b[i]) * (1-b[j]);chmin(cmin, now);}chmax(p[0][S], cmin);}rep(j, n) if (v[j] == 0) {ld cmax = 0;rep(i, n) if (v[i] == 0) {int x = S + pw3[i];int y = S + pw3[j] * 2;ld now = p[0][y] * b[j] + p[1][x] * (1-b[j]) * b[i];now /= 1 - (1-b[i]) * (1-b[j]);chmax(cmax, now);}chmin(p[1][S], cmax);}}cout << p[0][0] << '\n';return 0;}