#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,abm,mmx,tune=native") //#pragma clang diagnostic ignored "-Wunused-const-variable" #include<vector> #include<iostream> #include<stack> #include<cmath> #include<algorithm> #include<set> #include<map> #include<string> #include<tuple> #include<bitset> #include<queue> #include<unordered_map> #include<unordered_set> #include<random> #include<assert.h> #include<ctime> #include <cassert> #include <thread> #include <mutex> #include <semaphore> #include <chrono> //#define int long long #define all(a) a.begin(), a.end() typedef long long ll; typedef long double ld; typedef unsigned long long ull; using namespace std; ll gcd(ll i, ll j) { if (i < j)swap(i, j); if (j == 0)return i; else return gcd(j, i % j); } #ifdef _MY ll __builtin_popcount(ll x) { return x ? (__builtin_popcount(x >> 1) + (x & 1)) : 0; } #endif template<typename T> inline T getint() { T val = 0; char c; bool neg = false; while ((c = getchar()) && !(c >= '0' && c <= '9')) { neg |= c == '-'; } do { val = (val * 10) + c - '0'; } while ((c = getchar()) && (c >= '0' && c <= '9')); return val * (neg ? -1 : 1); } const ll INF = 1e7 + 100; const int mod = 998244353, mod1 = 1000000007; const ld eps = 1e-7, pi = acos(-1); const int maxT = 503, maxN = 100'100, A = 311; ll bp(ll et, ll b) { ll res = 1; for (int i = 30; i >= 0; --i) { res = (res * res) % mod; if ((b & (1 << i)) != 0)res = (res * et) % mod; } return res; } mt19937 mt_rand(time(0)); void panic() { cout << "No\n"; exit(0); } ld get_time() { ll tmr = clock(); return (ld)tmr / CLOCKS_PER_SEC; } int pl(int a, int b) { a += b; if (a >= mod) a -= mod; return a; } int mul(ll a, ll b) { return a * b % mod; } double dp[2][maxN]; void solve() { int n, t; cin >> n >> t; vector<double>p(n); for (auto& x : p) { //x = (double)(mt_rand() % 1'000'000) / 1'000'000; cin >> x; } sort(p.rbegin(), p.rend()); const ll K = 1000; dp[0][0] = 1; double ans = 0; int l = 0, r = 1; for (int i = 0; i < n; ++i) { vector<double>pp = { p[i],1 - p[i] }; double mx = 0; int ps = l - 1; int i1 = i % 2; int i2 = i1 ^ 1; for (int j = l; j < r; ++j) { for (int k = 0; k < pp.size(); ++k) { dp[i2][j + k] += dp[i1][j] * pp[k]; if (dp[i2][j + k] > mx) { mx = dp[i2][j + k]; ps = j + k; } } dp[i1][j] = 0; } int l1 = max(0LL, ps - K); int r1 = min(ps + K, (ll)n + 1); double tans = 0; const int can_do_err = i + 1 >= t ? (i + 1 - t) / 2 : -1; for (int t = l; t < r + 2; ++t) { if (t < l1 || t >= r1) { dp[i2][t] = 0; } else { if (t <= can_do_err) { tans += dp[i2][t]; } } } l = l1; r = r1; ans = max(ans, tans); } cout << fixed << ans << "\n"; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(14); #ifdef _MY freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); /*time_t start, end; time(&start);*/ #else //freopen("epic.in", "r", stdin); freopen("epic.out", "w", stdout); #endif // init(); int t = 1; //cin >> t; while (t--) { solve(); } #ifdef _MY cout << "Time taken is : " << fixed << get_time() << " sec " << "\n"; #endif 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 161 | #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,abm,mmx,tune=native") //#pragma clang diagnostic ignored "-Wunused-const-variable" #include<vector> #include<iostream> #include<stack> #include<cmath> #include<algorithm> #include<set> #include<map> #include<string> #include<tuple> #include<bitset> #include<queue> #include<unordered_map> #include<unordered_set> #include<random> #include<assert.h> #include<ctime> #include <cassert> #include <thread> #include <mutex> #include <semaphore> #include <chrono> //#define int long long #define all(a) a.begin(), a.end() typedef long long ll; typedef long double ld; typedef unsigned long long ull; using namespace std; ll gcd(ll i, ll j) { if (i < j)swap(i, j); if (j == 0)return i; else return gcd(j, i % j); } #ifdef _MY ll __builtin_popcount(ll x) { return x ? (__builtin_popcount(x >> 1) + (x & 1)) : 0; } #endif template<typename T> inline T getint() { T val = 0; char c; bool neg = false; while ((c = getchar()) && !(c >= '0' && c <= '9')) { neg |= c == '-'; } do { val = (val * 10) + c - '0'; } while ((c = getchar()) && (c >= '0' && c <= '9')); return val * (neg ? -1 : 1); } const ll INF = 1e7 + 100; const int mod = 998244353, mod1 = 1000000007; const ld eps = 1e-7, pi = acos(-1); const int maxT = 503, maxN = 100'100, A = 311; ll bp(ll et, ll b) { ll res = 1; for (int i = 30; i >= 0; --i) { res = (res * res) % mod; if ((b & (1 << i)) != 0)res = (res * et) % mod; } return res; } mt19937 mt_rand(time(0)); void panic() { cout << "No\n"; exit(0); } ld get_time() { ll tmr = clock(); return (ld)tmr / CLOCKS_PER_SEC; } int pl(int a, int b) { a += b; if (a >= mod) a -= mod; return a; } int mul(ll a, ll b) { return a * b % mod; } double dp[2][maxN]; void solve() { int n, t; cin >> n >> t; vector<double>p(n); for (auto& x : p) { //x = (double)(mt_rand() % 1'000'000) / 1'000'000; cin >> x; } sort(p.rbegin(), p.rend()); const ll K = 1000; dp[0][0] = 1; double ans = 0; int l = 0, r = 1; for (int i = 0; i < n; ++i) { vector<double>pp = { p[i],1 - p[i] }; double mx = 0; int ps = l - 1; int i1 = i % 2; int i2 = i1 ^ 1; for (int j = l; j < r; ++j) { for (int k = 0; k < pp.size(); ++k) { dp[i2][j + k] += dp[i1][j] * pp[k]; if (dp[i2][j + k] > mx) { mx = dp[i2][j + k]; ps = j + k; } } dp[i1][j] = 0; } int l1 = max(0LL, ps - K); int r1 = min(ps + K, (ll)n + 1); double tans = 0; const int can_do_err = i + 1 >= t ? (i + 1 - t) / 2 : -1; for (int t = l; t < r + 2; ++t) { if (t < l1 || t >= r1) { dp[i2][t] = 0; } else { if (t <= can_do_err) { tans += dp[i2][t]; } } } l = l1; r = r1; ans = max(ans, tans); } cout << fixed << ans << "\n"; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(14); #ifdef _MY freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); /*time_t start, end; time(&start);*/ #else //freopen("epic.in", "r", stdin); freopen("epic.out", "w", stdout); #endif // init(); int t = 1; //cin >> t; while (t--) { solve(); } #ifdef _MY cout << "Time taken is : " << fixed << get_time() << " sec " << "\n"; #endif return 0; } |