// Author: Olaf Surgut (surgutti)
// Created on 11-03-2025 12:27:37
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(x) begin(x),end(x)
#define FOR(i,l,r) for(int i=(l);i<=(r);i++)
#define ROF(i,r,l) for(int i=(r);i>=(l);i--)
auto& operator<<(auto &o, pair<auto, auto> p) {
return o << "(" << p.st << ", " << p.nd << ")";}
auto operator<<(auto &o, auto x)->decltype(end(x), o) {
o << "{"; int i=0; for (auto e : x) o << ","+!i++ << e;
return o << "}";}
#ifdef LOCAL
#define debug(x...) cerr << "[" #x "]: ", [](auto...$) { \
((cerr << $ << "; "),...) << endl; }(x)
#else
#define debug(...)
#endif
#define rep(i,a,b) for(int i = a; i < (b); i++)
using pii = pair<int, int>;
using vi = vector<int>;
// https://github.com/kth-competitive-programming/kactl/blob/main/content/numerical/FastFourierTransform.h
typedef complex<ld> C;
typedef vector<ld> vd;
void fft(vector<C>& a) {
int n = sz(a), L = 31 - __builtin_clz(n);
static vector<complex<ld>> R(2, 1);
static vector<C> rt(2, 1); // (^ 10% faster if double)
for (static int k = 2; k < n; k *= 2) {
R.resize(n); rt.resize(n);
auto x = polar(1.0L, acos(-1.0L) / k);
rep(i,k,2*k) rt[i] = R[i] = i&1 ? R[i/2] * x : R[i/2];
}
vi rev(n);
rep(i,0,n) rev[i] = (rev[i / 2] | (i & 1) << L) / 2;
rep(i,0,n) if (i < rev[i]) swap(a[i], a[rev[i]]);
for (int k = 1; k < n; k *= 2)
for (int i = 0; i < n; i += 2 * k) rep(j,0,k) {
// C z = rt[j+k] * a[i+j+k]; // (25% faster if hand-rolled) /// include-line
auto x = (ld *)&rt[j+k], y = (ld *)&a[i+j+k]; /// exclude-line
C z(x[0]*y[0] - x[1]*y[1], x[0]*y[1] + x[1]*y[0]); /// exclude-line
a[i + j + k] = a[i + j] - z;
a[i + j] += z;
}
}
vd conv(const vd& a, const vd& b) {
if (a.empty() || b.empty()) return {};
vd res(sz(a) + sz(b) - 1);
int L = 32 - __builtin_clz(sz(res)), n = 1 << L;
vector<C> in(n), out(n);
copy(all(a), begin(in));
rep(i,0,sz(b)) in[i].imag(b[i]);
fft(in);
for (C& x : in) x *= x;
rep(i,0,n) out[i] = in[-i & (n - 1)] - conj(in[i]);
fft(out);
rep(i,0,sz(res)) res[i] = imag(out[i]) / (4 * n);
return res;
}
const int N = 50000 + 7;
int n, t;
ld p[N], dp[N];
vd jazda(int l, int r) {
if (l > r) {
return {1};
}
if (l == r) {
return vd{1 - p[l], p[l]};
}
int m = (l + r) >> 1;
return conv(jazda(l, m), jazda(m + 1, r));
}
const ld eps = 1e-8;
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> t;
FOR(i, 1, n)
cin >> p[i];
sort(p + 1, p + 1 + n);
reverse(p + 1, p + 1 + n);
const int B = 9000;
while (n - 1 >= t && n >= B && p[n - B / 2] < 0.5)
n--;
auto P = jazda(1, t - 1);
FOR(i, 0, t - 1)
dp[i] = P[i];
ld ans = 0;
FOR(i, t, min(n, t + B)) {
ROF(j, i, 1) {
dp[j] *= (1 - p[i]);
dp[j] += p[i] * dp[j - 1];
}
dp[0] *= (1 - p[i]);
ld now = 0;
FOR(j, 0, i) if (2 * j - i >= t) {
now += dp[j];
}
if (ans < now) {
ans = now;
}
}
rep(i, 0, N)
dp[i] = 0;
int l = max(t, n - B);
P = jazda(1, l - 1);
FOR(i, 0, l - 1)
dp[i] = P[i];
FOR(i, l, n) {
ROF(j, i, 1) {
dp[j] *= (1 - p[i]);
dp[j] += p[i] * dp[j - 1];
}
dp[0] *= (1 - p[i]);
ld now = 0;
FOR(j, 0, i) if (2 * j - i >= t) {
now += dp[j];
}
if (ans < now) {
ans = now;
}
}
cout << fixed << setprecision(9) << ans << '\n';
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | // Author: Olaf Surgut (surgutti) // Created on 11-03-2025 12:27:37 #include "bits/stdc++.h" using namespace std; #define int long long #define ll long long #define ld long double #define endl '\n' #define st first #define nd second #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define all(x) begin(x),end(x) #define FOR(i,l,r) for(int i=(l);i<=(r);i++) #define ROF(i,r,l) for(int i=(r);i>=(l);i--) auto& operator<<(auto &o, pair<auto, auto> p) { return o << "(" << p.st << ", " << p.nd << ")";} auto operator<<(auto &o, auto x)->decltype(end(x), o) { o << "{"; int i=0; for (auto e : x) o << ","+!i++ << e; return o << "}";} #ifdef LOCAL #define debug(x...) cerr << "[" #x "]: ", [](auto...$) { \ ((cerr << $ << "; "),...) << endl; }(x) #else #define debug(...) #endif #define rep(i,a,b) for(int i = a; i < (b); i++) using pii = pair<int, int>; using vi = vector<int>; // https://github.com/kth-competitive-programming/kactl/blob/main/content/numerical/FastFourierTransform.h typedef complex<ld> C; typedef vector<ld> vd; void fft(vector<C>& a) { int n = sz(a), L = 31 - __builtin_clz(n); static vector<complex<ld>> R(2, 1); static vector<C> rt(2, 1); // (^ 10% faster if double) for (static int k = 2; k < n; k *= 2) { R.resize(n); rt.resize(n); auto x = polar(1.0L, acos(-1.0L) / k); rep(i,k,2*k) rt[i] = R[i] = i&1 ? R[i/2] * x : R[i/2]; } vi rev(n); rep(i,0,n) rev[i] = (rev[i / 2] | (i & 1) << L) / 2; rep(i,0,n) if (i < rev[i]) swap(a[i], a[rev[i]]); for (int k = 1; k < n; k *= 2) for (int i = 0; i < n; i += 2 * k) rep(j,0,k) { // C z = rt[j+k] * a[i+j+k]; // (25% faster if hand-rolled) /// include-line auto x = (ld *)&rt[j+k], y = (ld *)&a[i+j+k]; /// exclude-line C z(x[0]*y[0] - x[1]*y[1], x[0]*y[1] + x[1]*y[0]); /// exclude-line a[i + j + k] = a[i + j] - z; a[i + j] += z; } } vd conv(const vd& a, const vd& b) { if (a.empty() || b.empty()) return {}; vd res(sz(a) + sz(b) - 1); int L = 32 - __builtin_clz(sz(res)), n = 1 << L; vector<C> in(n), out(n); copy(all(a), begin(in)); rep(i,0,sz(b)) in[i].imag(b[i]); fft(in); for (C& x : in) x *= x; rep(i,0,n) out[i] = in[-i & (n - 1)] - conj(in[i]); fft(out); rep(i,0,sz(res)) res[i] = imag(out[i]) / (4 * n); return res; } const int N = 50000 + 7; int n, t; ld p[N], dp[N]; vd jazda(int l, int r) { if (l > r) { return {1}; } if (l == r) { return vd{1 - p[l], p[l]}; } int m = (l + r) >> 1; return conv(jazda(l, m), jazda(m + 1, r)); } const ld eps = 1e-8; signed main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> t; FOR(i, 1, n) cin >> p[i]; sort(p + 1, p + 1 + n); reverse(p + 1, p + 1 + n); const int B = 9000; while (n - 1 >= t && n >= B && p[n - B / 2] < 0.5) n--; auto P = jazda(1, t - 1); FOR(i, 0, t - 1) dp[i] = P[i]; ld ans = 0; FOR(i, t, min(n, t + B)) { ROF(j, i, 1) { dp[j] *= (1 - p[i]); dp[j] += p[i] * dp[j - 1]; } dp[0] *= (1 - p[i]); ld now = 0; FOR(j, 0, i) if (2 * j - i >= t) { now += dp[j]; } if (ans < now) { ans = now; } } rep(i, 0, N) dp[i] = 0; int l = max(t, n - B); P = jazda(1, l - 1); FOR(i, 0, l - 1) dp[i] = P[i]; FOR(i, l, n) { ROF(j, i, 1) { dp[j] *= (1 - p[i]); dp[j] += p[i] * dp[j - 1]; } dp[0] *= (1 - p[i]); ld now = 0; FOR(j, 0, i) if (2 * j - i >= t) { now += dp[j]; } if (ans < now) { ans = now; } } cout << fixed << setprecision(9) << ans << '\n'; return 0; } |
English