problem_id
stringlengths 6
6
| language
stringclasses 2
values | original_status
stringclasses 3
values | original_src
stringlengths 19
243k
| changed_src
stringlengths 19
243k
| change
stringclasses 3
values | i1
int64 0
8.44k
| i2
int64 0
8.44k
| j1
int64 0
8.44k
| j2
int64 0
8.44k
| error
stringclasses 270
values | stderr
stringlengths 0
226k
|
---|---|---|---|---|---|---|---|---|---|---|---|
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD 1000000007
#define nl cout << endl
#define rt ll Q[100005] = {0}
#define mp make_pair
#define test() \
ull t; \
cin >> t; \
while (t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define oa(a, n) \
for (ll i = 0; i < n; i++) \
cout << a[i] << " "; \
nl
#define cn(a, n) \
for (ll i = 0; i < n; i++) \
cin >> a[i]
#define ov(a) \
for (ll i = 0; i < a.size(); i++) \
cout << a[i] << " "; \
nl
#define fastio() \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
int main() {
fastio();
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("outpu.txt", "w", stdout);
#endif
ll N;
cin >> N;
dd ar[N];
cn(ar, N);
dd ans[N + 1][N + 1];
for (ll i = 0; i <= N; i++) {
for (ll j = 0; j <= N; j++) {
ans[i][j] = 0.0;
}
}
ans[0][0] = 1.0;
for (ll i = 1; i <= N; i++) {
ans[i][0] = ans[i - 1][0] * (1 - ar[i - 1]);
}
ans[1][1] = ar[0];
for (ll i = 2; i <= N; i++) {
for (ll j = 1; j < i; j++) {
ans[i][j] =
(ans[i - 1][j - 1] * ar[i - 1] + ans[i - 1][j] * (1 - ar[i - 1]));
}
ans[i][i] = ans[i - 1][i - 1] * ar[i - 1];
}
dd sum = 0.0;
for (ll i = N / 2 + 1; i <= N; i++)
sum += ans[N][i];
cout << fixed << showpoint;
cout << setprecision(12);
cout << sum << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD 1000000007
#define nl cout << endl
#define rt ll Q[100005] = {0}
#define mp make_pair
#define test() \
ull t; \
cin >> t; \
while (t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define oa(a, n) \
for (ll i = 0; i < n; i++) \
cout << a[i] << " "; \
nl
#define cn(a, n) \
for (ll i = 0; i < n; i++) \
cin >> a[i]
#define ov(a) \
for (ll i = 0; i < a.size(); i++) \
cout << a[i] << " "; \
nl
#define fastio() \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
int main() {
fastio();
ll N;
cin >> N;
dd ar[N];
cn(ar, N);
dd ans[N + 1][N + 1];
for (ll i = 0; i <= N; i++) {
for (ll j = 0; j <= N; j++) {
ans[i][j] = 0.0;
}
}
ans[0][0] = 1.0;
for (ll i = 1; i <= N; i++) {
ans[i][0] = ans[i - 1][0] * (1 - ar[i - 1]);
}
ans[1][1] = ar[0];
for (ll i = 2; i <= N; i++) {
for (ll j = 1; j < i; j++) {
ans[i][j] =
(ans[i - 1][j - 1] * ar[i - 1] + ans[i - 1][j] * (1 - ar[i - 1]));
}
ans[i][i] = ans[i - 1][i - 1] * ar[i - 1];
}
dd sum = 0.0;
for (ll i = N / 2 + 1; i <= N; i++)
sum += ans[N][i];
cout << fixed << showpoint;
cout << setprecision(12);
cout << sum << endl;
}
| delete | 35 | 39 | 35 | 35 | -11 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i < b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
#define trace(x) cout << #x << "=" << x << "\n";
#define sz(x) (int)(x.size())
#define mod 1000000007
template <typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
typename vector<T>::const_iterator it;
for (it = v.begin(); it != v.end(); it++) {
if (it != v.begin())
os << ", ";
os << *it;
}
return os << "}";
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
os << "[";
typename set<T>::const_iterator it;
for (it = v.begin(); it != v.end(); it++) {
if (it != v.begin())
os << ", ";
os << *it;
}
return os << "]";
}
template <typename F, typename S>
ostream &operator<<(ostream &os, const map<F, S> &v) {
os << "[";
typename map<F, S>::const_iterator it;
for (it = v.begin(); it != v.end(); it++) {
if (it != v.begin())
os << ", ";
os << it->first << " = " << it->second;
}
return os << "]";
}
#define deb(x) cerr << #x << " = " << x << endl;
vector<double> a;
double dp[3005][3005];
double fun(int i, int k) {
// deb(i);
// deb(k);
if (k > i) {
return 0;
}
if (i == 1) {
if (k == 1) {
return a[i];
}
if (k == 0) {
double ans = 1 - a[i];
return ans;
}
}
if (dp[i][k] != -1) {
return dp[i][k];
}
dp[i][k] = a[i] * fun(i - 1, k - 1) + (1 - a[i]) * fun(i - 1, k);
return dp[i][k];
}
int32_t main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
a.resize(n + 1);
for (int i = 0; i < 3005; i++) {
for (int j = 0; j < 3005; j++) {
dp[i][j] = -1;
}
}
REP(i, 1, n + 1) { cin >> a[i]; }
double ans = 0;
for (int i = (n / 2) + 1; i <= n; i++) {
ans += fun(n, i);
}
printf("%0.12lf\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i < b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
#define trace(x) cout << #x << "=" << x << "\n";
#define sz(x) (int)(x.size())
#define mod 1000000007
template <typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
typename vector<T>::const_iterator it;
for (it = v.begin(); it != v.end(); it++) {
if (it != v.begin())
os << ", ";
os << *it;
}
return os << "}";
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
os << "[";
typename set<T>::const_iterator it;
for (it = v.begin(); it != v.end(); it++) {
if (it != v.begin())
os << ", ";
os << *it;
}
return os << "]";
}
template <typename F, typename S>
ostream &operator<<(ostream &os, const map<F, S> &v) {
os << "[";
typename map<F, S>::const_iterator it;
for (it = v.begin(); it != v.end(); it++) {
if (it != v.begin())
os << ", ";
os << it->first << " = " << it->second;
}
return os << "]";
}
#define deb(x) cerr << #x << " = " << x << endl;
vector<double> a;
double dp[3005][3005];
double fun(int i, int k) {
// deb(i);
// deb(k);
if (k < 0) {
return 0;
}
if (k > i) {
return 0;
}
if (i == 1) {
if (k == 1) {
return a[i];
}
if (k == 0) {
double ans = 1 - a[i];
return ans;
}
}
if (dp[i][k] != -1) {
return dp[i][k];
}
dp[i][k] = a[i] * fun(i - 1, k - 1) + (1 - a[i]) * fun(i - 1, k);
return dp[i][k];
}
int32_t main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
a.resize(n + 1);
for (int i = 0; i < 3005; i++) {
for (int j = 0; j < 3005; j++) {
dp[i][j] = -1;
}
}
REP(i, 1, n + 1) { cin >> a[i]; }
double ans = 0;
for (int i = (n / 2) + 1; i <= n; i++) {
ans += fun(n, i);
}
printf("%0.12lf\n", ans);
return 0;
} | insert | 62 | 62 | 62 | 65 | 0 | |
p03168 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3001;
double dp[N][N];
bool vis[N][N];
double p[N];
int n;
double rec(int i, int h) {
if (i == n) {
return double(h > (n - h));
}
auto &res = dp[i][h];
if (vis[i][h])
return res;
return res = p[i] * rec(i + 1, h + 1) + (1 - p[i]) * (rec(i + 1, h));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.precision(20);
cout << fixed;
memset(dp, 0, sizeof dp);
memset(vis, false, sizeof vis);
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> p[i];
}
cout << rec(0, 0) << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3001;
double dp[N][N];
bool vis[N][N];
double p[N];
int n;
double rec(int i, int h) {
if (i == n) {
return double(h > (n - h));
}
auto &res = dp[i][h];
if (vis[i][h])
return res;
vis[i][h] = true;
return res = p[i] * rec(i + 1, h + 1) + (1 - p[i]) * (rec(i + 1, h));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.precision(20);
cout << fixed;
memset(dp, 0, sizeof dp);
memset(vis, false, sizeof vis);
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> p[i];
}
cout << rec(0, 0) << '\n';
return 0;
} | insert | 17 | 17 | 17 | 18 | TLE | |
p03168 | C++ | Runtime Error | // https://atcoder.jp/contests/dp/tasks/dp_i
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define EPS (1e-7)
#define INF (1e9)
#define MODI (1000000007)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
// dp[i][j] : コインをi枚使い、j枚が表である確率
// double dp[3001][3001];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
// 入力、DP後、DP前
vector<double> p(n), dpA(n, 0), dpB(n, 0);
for (int i = 0; i < n; i++) {
cin >> p[i];
}
dpB[0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= i; j++) {
// i-1回目で表の枚数がj-1で、i回目が表
// i-1回目で表の枚数がjで、i回目が裏
dpA[j] = dpB[j - 1] * p[i - 1] + dpB[j] * (1.0 - p[i - 1]);
}
swap(dpB, dpA);
}
double ans = 0;
for (int i = n / 2 + 1; i <= n; i++) {
ans += dpB[i];
}
printf("%0.10f\n", ans);
return 0;
} | // https://atcoder.jp/contests/dp/tasks/dp_i
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define EPS (1e-7)
#define INF (1e9)
#define MODI (1000000007)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
// dp[i][j] : コインをi枚使い、j枚が表である確率
// double dp[3001][3001];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
// 入力、DP後、DP前
vector<double> p(n), dpA(n + 1, 0), dpB(n + 1, 0);
for (int i = 0; i < n; i++) {
cin >> p[i];
}
dpB[0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= i; j++) {
// i-1回目で表の枚数がj-1で、i回目が表
// i-1回目で表の枚数がjで、i回目が裏
dpA[j] = dpB[j - 1] * p[i - 1] + dpB[j] * (1.0 - p[i - 1]);
}
swap(dpB, dpA);
}
double ans = 0;
for (int i = n / 2 + 1; i <= n; i++) {
ans += dpB[i];
}
printf("%0.10f\n", ans);
return 0;
} | replace | 26 | 27 | 26 | 27 | -6 | munmap_chunk(): invalid pointer
|
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ld long double
const int N = 1e3 + 5;
int n;
ld prob[N];
ld dp[N][N];
ld go(int idx, int heads) {
if (idx > n) {
int tails = n - heads;
if (heads > tails)
return 1;
return 0;
}
if (dp[idx][heads] >= 0)
return dp[idx][heads];
ld ans = go(idx + 1, heads + 1) * prob[idx] +
go(idx + 1, heads) * (1.0 - prob[idx]);
return dp[idx][heads] = ans;
}
void solve() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> prob[i];
}
memset(dp, -1, sizeof(dp));
ld ans = go(1, 0);
cout << fixed << setprecision(10);
cout << ans;
}
int main() {
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ld long double
const int N = 3e3 + 5;
int n;
ld prob[N];
ld dp[N][N];
ld go(int idx, int heads) {
if (idx > n) {
int tails = n - heads;
if (heads > tails)
return 1;
return 0;
}
if (dp[idx][heads] >= 0)
return dp[idx][heads];
ld ans = go(idx + 1, heads + 1) * prob[idx] +
go(idx + 1, heads) * (1.0 - prob[idx]);
return dp[idx][heads] = ans;
}
void solve() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> prob[i];
}
memset(dp, -1, sizeof(dp));
ld ans = go(1, 0);
cout << fixed << setprecision(10);
cout << ans;
}
int main() {
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p03168 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define N 3001
int n;
int vis[N][N] = {0};
double dp[N][N], a[N], ans = 0;
double solve(int i, int c, float p = 0) {
if (i == n) {
if (c > n / 2)
return 1;
return 0;
}
if (vis[i][c])
return dp[i][c];
return dp[i][c] = a[i] * solve(i + 1, c + 1) + (1 - a[i]) * solve(i + 1, c);
}
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
ans = solve(0, 0, 1);
cout << setprecision(10) << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define N 3001
int n;
int vis[N][N] = {0};
double dp[N][N], a[N], ans = 0;
double solve(int i, int c, float p = 0) {
if (i == n) {
if (c > n / 2)
return 1;
return 0;
}
if (vis[i][c])
return dp[i][c];
vis[i][c] = 1;
return dp[i][c] = a[i] * solve(i + 1, c + 1) + (1 - a[i]) * solve(i + 1, c);
}
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
ans = solve(0, 0, 1);
cout << setprecision(10) << ans << endl;
return 0;
}
| insert | 18 | 18 | 18 | 19 | TLE | |
p03168 | C++ | Time Limit Exceeded | /*
@author: Charan Sai
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define int long long
#define ppi pair<int, int>
#define endl "\n"
#define nl cout << "\n"
#define deb(x) cout << #x << " " << x << endl;
double head_prob[3000];
double dp[3000][3000];
int n;
// Base Case construction is really crucial
double Top_Down(int i, int heads) {
// Base Case
if (i == 0 && heads == 0)
return 1;
if (i == 0 && heads != 0)
return 0;
if (dp[i][heads] != 0)
return dp[i][heads];
// Choice
if (heads == 0) {
// Return prob of tail only
return (dp[i][heads] = Top_Down(i - 1, heads) * (1 - head_prob[i]));
} else if (i > heads) {
return (dp[i][heads] = Top_Down(i - 1, heads - 1) * head_prob[i] +
Top_Down(i - 1, heads) * (1 - head_prob[i]));
}
return (dp[i][heads] = Top_Down(i - 1, heads - 1) * head_prob[i]);
}
void Bottom_Up() {
dp[0][0] = 1;
for (int j = 1; j <= n; ++j)
dp[0][j] = 0;
for (int i = 1; i <= n; ++i) {
for (int heads = 0; heads <= n; ++heads) {
if (heads == 0)
dp[i][heads] = dp[i - 1][heads] * (1 - head_prob[i]);
else if (i > heads) {
dp[i][heads] = dp[i - 1][heads - 1] * head_prob[i] +
dp[i - 1][heads] * (1 - head_prob[i]);
} else
dp[i][heads] = dp[i - 1][heads - 1] * head_prob[i];
}
}
double total_prob = 0.0;
for (int heads = n / 2 + 1; heads <= n; ++heads) {
total_prob += dp[n][heads];
}
cout << setprecision(10) << total_prob << endl;
}
int32_t main() {
IOS;
memset(dp, 0, sizeof(dp));
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> head_prob[i];
}
double total_prob = 0.0;
for (int heads = n / 2 + 1; heads <= n; ++heads) {
// cout << Top_Down(n, heads);
total_prob += Top_Down(n, heads);
}
Bottom_Up();
} | /*
@author: Charan Sai
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define int long long
#define ppi pair<int, int>
#define endl "\n"
#define nl cout << "\n"
#define deb(x) cout << #x << " " << x << endl;
double head_prob[3000];
double dp[3000][3000];
int n;
// Base Case construction is really crucial
double Top_Down(int i, int heads) {
// Base Case
if (i == 0 && heads == 0)
return 1;
if (i == 0 && heads != 0)
return 0;
if (dp[i][heads] != 0)
return dp[i][heads];
// Choice
if (heads == 0) {
// Return prob of tail only
return (dp[i][heads] = Top_Down(i - 1, heads) * (1 - head_prob[i]));
} else if (i > heads) {
return (dp[i][heads] = Top_Down(i - 1, heads - 1) * head_prob[i] +
Top_Down(i - 1, heads) * (1 - head_prob[i]));
}
return (dp[i][heads] = Top_Down(i - 1, heads - 1) * head_prob[i]);
}
void Bottom_Up() {
dp[0][0] = 1;
for (int j = 1; j <= n; ++j)
dp[0][j] = 0;
for (int i = 1; i <= n; ++i) {
for (int heads = 0; heads <= n; ++heads) {
if (heads == 0)
dp[i][heads] = dp[i - 1][heads] * (1 - head_prob[i]);
else if (i > heads) {
dp[i][heads] = dp[i - 1][heads - 1] * head_prob[i] +
dp[i - 1][heads] * (1 - head_prob[i]);
} else
dp[i][heads] = dp[i - 1][heads - 1] * head_prob[i];
}
}
double total_prob = 0.0;
for (int heads = n / 2 + 1; heads <= n; ++heads) {
total_prob += dp[n][heads];
}
cout << setprecision(10) << total_prob << endl;
}
int32_t main() {
IOS;
memset(dp, 0, sizeof(dp));
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> head_prob[i];
}
Bottom_Up();
} | delete | 74 | 79 | 74 | 74 | TLE | |
p03168 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define DEBUG 0
#define nl '\n'
#define fori(n) for (int i = 0; i < n; ++i)
#define forj(n) for (int j = 0; j < n; ++j)
#define fork(n) for (int k = 0; k < n; ++k)
#define forl(n) for (int l = 0; l < n; ++l)
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define ppb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<bool> vbool;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef long double ld;
typedef vector<vector<int>> vvi;
typedef vector<vbool> vvb;
const ll N = 100010;
const ll INF = 0x3f3f3f3f;
const ll MOD = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<ld> a(n);
fori(n) { cin >> a[i]; }
vector<vector<ld>> dp(n + 1, vector<ld>(n + 1, 1.0));
fori(n + 1) forj(n + 1) if (j > i) dp[i][j] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= n; ++j) {
dp[i][j] = dp[i - 1][j] * (1 - a[i - 1]);
if (j > 0)
dp[i][j] += dp[i - 1][j - 1] * a[i - 1];
}
}
fori(n + 1) {
forj(n + 1) cerr << dp[i][j] << " ";
cerr << nl;
}
ld ans = 0;
for (int j = n / 2 + 1; j <= n; ++j)
ans += dp[n][j];
cout << fixed << setprecision(10) << ans << nl;
#if DEBUG
cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << " s" << nl;
#endif
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define DEBUG 0
#define nl '\n'
#define fori(n) for (int i = 0; i < n; ++i)
#define forj(n) for (int j = 0; j < n; ++j)
#define fork(n) for (int k = 0; k < n; ++k)
#define forl(n) for (int l = 0; l < n; ++l)
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define ppb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<bool> vbool;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef long double ld;
typedef vector<vector<int>> vvi;
typedef vector<vbool> vvb;
const ll N = 100010;
const ll INF = 0x3f3f3f3f;
const ll MOD = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<ld> a(n);
fori(n) { cin >> a[i]; }
vector<vector<ld>> dp(n + 1, vector<ld>(n + 1, 1.0));
fori(n + 1) forj(n + 1) if (j > i) dp[i][j] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= n; ++j) {
dp[i][j] = dp[i - 1][j] * (1 - a[i - 1]);
if (j > 0)
dp[i][j] += dp[i - 1][j - 1] * a[i - 1];
}
}
ld ans = 0;
for (int j = n / 2 + 1; j <= n; ++j)
ans += dp[n][j];
cout << fixed << setprecision(10) << ans << nl;
#if DEBUG
cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << " s" << nl;
#endif
return 0;
}
| delete | 45 | 50 | 45 | 45 | TLE | |
p03168 | C++ | Runtime Error | #include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<double> p(N);
for (int i = 0; i < N; i++) {
cin >> p[i];
}
double dp[3000][3000];
for (int i = 0; i < 3000; i++) {
for (int j = 0; j < 3000; j++) {
dp[i][j] = 0;
}
} // 初期化
dp[0][0] = 1.0;
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= i; j++) {
dp[i + 1][j + 1] += dp[i][j] * p[i];
dp[i + 1][j] += dp[i][j] * (1.0 - p[i]);
}
}
double sum = 0;
for (int j = (N + 1) / 2; j <= N; j++) {
sum += dp[N][j];
}
cout << setprecision(10) << sum << endl;
return 0;
}
| #include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<double> p(N);
for (int i = 0; i < N; i++) {
cin >> p[i];
}
double dp[3000][3000];
for (int i = 0; i < 3000; i++) {
for (int j = 0; j < 3000; j++) {
dp[i][j] = 0;
}
} // 初期化
dp[0][0] = 1.0;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= i; j++) {
dp[i + 1][j + 1] += dp[i][j] * p[i];
dp[i + 1][j] += dp[i][j] * (1.0 - p[i]);
}
}
double sum = 0;
for (int j = (N + 1) / 2; j <= N; j++) {
sum += dp[N][j];
}
cout << setprecision(10) << sum << endl;
return 0;
}
| replace | 23 | 24 | 23 | 24 | -11 | |
p03168 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repA(i, a, b) for (ll i = a; i <= b; i++)
#define repD(i, b, a) for (int i = b; i >= a; i--)
#define fill(a, val) memset(a, val, sizeof(a))
#define f first
#define s second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int mod = 1000000007;
const int maxN = 3000;
double p[maxN];
double dp[maxN][maxN];
int n;
double solve(int id, int h_cnt) {
if (h_cnt == 0)
return 1;
if (id == 0)
return 0;
if (dp[id][h_cnt] > 0.9)
return dp[id][h_cnt];
return dp[id][h_cnt] = p[id] * solve(id - 1, h_cnt - 1) +
(1 - p[id]) * solve(id - 1, h_cnt);
// return ans;
}
int main() {
cin >> n;
repA(i, 1, n) cin >> p[i];
fill(dp, -1);
cout << fixed << setprecision(10);
cout << solve(n, (n + 1) / 2) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repA(i, a, b) for (ll i = a; i <= b; i++)
#define repD(i, b, a) for (int i = b; i >= a; i--)
#define fill(a, val) memset(a, val, sizeof(a))
#define f first
#define s second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int mod = 1000000007;
const int maxN = 3000;
double p[maxN];
double dp[maxN][maxN];
int n;
double solve(int id, int h_cnt) {
if (h_cnt == 0)
return 1;
if (id == 0)
return 0;
if (dp[id][h_cnt] > -0.9)
return dp[id][h_cnt];
return dp[id][h_cnt] = p[id] * solve(id - 1, h_cnt - 1) +
(1 - p[id]) * solve(id - 1, h_cnt);
// return ans;
}
int main() {
cin >> n;
repA(i, 1, n) cin >> p[i];
fill(dp, -1);
cout << fixed << setprecision(10);
cout << solve(n, (n + 1) / 2) << endl;
return 0;
}
| replace | 23 | 24 | 23 | 24 | TLE | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int u = 1e5 + 5;
int main() {
int n;
cin >> n;
long double a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
if (n > 2) {
long double dp[n + 1][n + 1];
memset(dp, 0, sizeof dp);
dp[0][0] = 1;
for (int i = 1; i <= n; i++)
dp[i][0] = dp[i - 1][0] * (1 - a[i - 1]);
for (int i = 1; i <= n; i++)
dp[0][i] = dp[0][i - 1] * (a[i - 1]);
for (int i = 1; i < n - i; i++)
for (int j = 1; j <= n; j++) {
dp[i][j] =
dp[i][j - 1] * (a[i + j - 1]) + dp[i - 1][j] * (1 - a[i + j - 1]);
}
double d = 0;
for (int i = n; i >= (n + 1) / 2; i--)
d += dp[n - i][i];
cout << fixed << setprecision(9) << d;
} else {
long double d = 1;
for (int i = 0; i < n; i++)
d *= a[i];
cout << fixed << setprecision(9) << d;
}
} | #include <bits/stdc++.h>
using namespace std;
int u = 1e5 + 5;
int main() {
int n;
cin >> n;
long double a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
if (n > 2) {
long double dp[n + 1][n + 1];
memset(dp, 0, sizeof dp);
dp[0][0] = 1;
for (int i = 1; i <= n; i++)
dp[i][0] = dp[i - 1][0] * (1 - a[i - 1]);
for (int i = 1; i <= n; i++)
dp[0][i] = dp[0][i - 1] * (a[i - 1]);
dp[0][0] = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n - i; j++) {
dp[i][j] =
dp[i][j - 1] * (a[i + j - 1]) + dp[i - 1][j] * (1 - a[i + j - 1]);
}
double d = 0;
for (int i = n; i >= (n + 1) / 2; i--)
d += dp[n - i][i];
cout << fixed << setprecision(9) << d;
} else {
long double d = 1;
for (int i = 0; i < n; i++)
d *= a[i];
cout << fixed << setprecision(9) << d;
}
} | replace | 18 | 21 | 18 | 21 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr, A) for (auto itr = A.begin(); itr != A.end(); itr++)
template <class T>
using reversed_priority_queue = priority_queue<T, vector<T>, greater<T>>;
typedef long long llong;
char moji[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
char moji2[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
char moji3[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
#define Sort(a) sort(a.begin(), a.end());
#define Reverse(a) reverse(a.begin(), a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9 + 7)
#define MAX int(2 * 1e5 + 5)
#define debug(x) cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
void myprint(int *A, int A_num) {
REP(i, A_num) cout << A[i] << " ";
cout << endl;
}
const int n_max = 305;
signed main() {
int n;
cin >> n;
double p[n];
REP(i, n) cin >> p[i];
double dp[n_max][n_max];
REP(i, n + 1) REP(j, i + 1) dp[i][j] = 0.0;
dp[0][0] = 1.0;
REP(i, n) {
REP(j, i + 2) {
if (j != 0 and j != i + 1) {
dp[i + 1][j] = p[i] * dp[i][j - 1] + (1 - p[i]) * dp[i][j];
} else if (j == 0) {
dp[i + 1][j] = (1 - p[i]) * dp[i][j];
} else
dp[i + 1][j] = p[i] * dp[i][j - 1];
}
}
double ans = 0.0;
FOR(i, n / 2 + 1, n + 1) { ans += dp[n][i]; }
cout << fixed << setprecision(12) << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr, A) for (auto itr = A.begin(); itr != A.end(); itr++)
template <class T>
using reversed_priority_queue = priority_queue<T, vector<T>, greater<T>>;
typedef long long llong;
char moji[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
char moji2[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
char moji3[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
#define Sort(a) sort(a.begin(), a.end());
#define Reverse(a) reverse(a.begin(), a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9 + 7)
#define MAX int(2 * 1e5 + 5)
#define debug(x) cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
void myprint(int *A, int A_num) {
REP(i, A_num) cout << A[i] << " ";
cout << endl;
}
const int n_max = 3005;
signed main() {
int n;
cin >> n;
double p[n];
REP(i, n) cin >> p[i];
double dp[n_max][n_max];
REP(i, n + 1) REP(j, i + 1) dp[i][j] = 0.0;
dp[0][0] = 1.0;
REP(i, n) {
REP(j, i + 2) {
if (j != 0 and j != i + 1) {
dp[i + 1][j] = p[i] * dp[i][j - 1] + (1 - p[i]) * dp[i][j];
} else if (j == 0) {
dp[i + 1][j] = (1 - p[i]) * dp[i][j];
} else
dp[i + 1][j] = p[i] * dp[i][j - 1];
}
}
double ans = 0.0;
FOR(i, n / 2 + 1, n + 1) { ans += dp[n][i]; }
cout << fixed << setprecision(12) << ans << endl;
} | replace | 47 | 48 | 47 | 48 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define dbg(n) cout << '\n' << #n << " is " << n << '\n';
#define pb push_back
#define all(v) v.begin(), v.end()
#define cs(i) cout << "Case " << i + 1 << ": \n";
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
const int N = 1e3 + 5;
const int INF = 0x7fffffff;
double p[N];
double dp[N][N];
int main() {
int n, t, hold = 0;
cin >> n;
for (int i = 0; i < n; i++)
cin >> p[i];
dp[0][0] = 1.00;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= i; j++) {
if (j)
dp[i][j] += dp[i - 1][j - 1] * p[i - 1];
dp[i][j] += dp[i - 1][j] * (1.0 - p[i - 1]);
}
}
double ans = 0;
for (int i = 0; i <= n; i++)
if (i > n - i)
ans += dp[n][i];
/*dbg(n)
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
cout<<dp[i][j]<<" ";
} cout<<endl;
}*/
cout << fixed << setprecision(12);
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define dbg(n) cout << '\n' << #n << " is " << n << '\n';
#define pb push_back
#define all(v) v.begin(), v.end()
#define cs(i) cout << "Case " << i + 1 << ": \n";
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
const int N = 3e3 + 5;
const int INF = 0x7fffffff;
double p[N];
double dp[N][N];
int main() {
int n, t, hold = 0;
cin >> n;
for (int i = 0; i < n; i++)
cin >> p[i];
dp[0][0] = 1.00;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= i; j++) {
if (j)
dp[i][j] += dp[i - 1][j - 1] * p[i - 1];
dp[i][j] += dp[i - 1][j] * (1.0 - p[i - 1]);
}
}
double ans = 0;
for (int i = 0; i <= n; i++)
if (i > n - i)
ans += dp[n][i];
/*dbg(n)
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
cout<<dp[i][j]<<" ";
} cout<<endl;
}*/
cout << fixed << setprecision(12);
cout << ans << endl;
return 0;
}
| replace | 13 | 14 | 13 | 14 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
#define N 1010
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define pp pop_back
#define mapiter map<int, int>::iterator
#define forn(i, n) for (int i = 0; i < n; ++i)
#define forn1(i, n) for (int i = 1; i <= n; ++i)
#define forr(i, n) for (int i = n - 1; i >= 0; --i)
#define forr1(i, n) for (int i = n; i >= 1; --i)
#define form(l, r, i) for (int i = l; i <= r; ++i)
#define forv(r, l, i) for (int i = r; i >= l; --i)
#define r0 return 0
#define barnarnar \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define lld long double
#define elif else if
const ll inf = 1e9 + 7;
const lld EPS = 0.00000001;
const ll modw = 1e9 + 7;
using namespace std;
lld dp[N][N]; // pref:tails
lld a[N];
int main() {
barnarnar int n;
cin >> n;
forn1(i, n) cin >> a[i];
dp[0][0] = 1;
forn1(i, n) {
for (int j = 0; j <= i; j++) {
dp[i][j] = dp[i - 1][j] * (1 - a[i]) + dp[i - 1][j - 1] * a[i];
}
}
lld ans = 0;
for (int i = n / 2 + n % 2; i <= n; i++)
ans += dp[n][i];
cout << setprecision(10) << fixed;
cout << ans;
return 0;
}
/*
5
11000
11100
01100
00000
00000
*/ | #include <bits/stdc++.h>
#define N 3010
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define pp pop_back
#define mapiter map<int, int>::iterator
#define forn(i, n) for (int i = 0; i < n; ++i)
#define forn1(i, n) for (int i = 1; i <= n; ++i)
#define forr(i, n) for (int i = n - 1; i >= 0; --i)
#define forr1(i, n) for (int i = n; i >= 1; --i)
#define form(l, r, i) for (int i = l; i <= r; ++i)
#define forv(r, l, i) for (int i = r; i >= l; --i)
#define r0 return 0
#define barnarnar \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define lld long double
#define elif else if
const ll inf = 1e9 + 7;
const lld EPS = 0.00000001;
const ll modw = 1e9 + 7;
using namespace std;
lld dp[N][N]; // pref:tails
lld a[N];
int main() {
barnarnar int n;
cin >> n;
forn1(i, n) cin >> a[i];
dp[0][0] = 1;
forn1(i, n) {
for (int j = 0; j <= i; j++) {
dp[i][j] = dp[i - 1][j] * (1 - a[i]) + dp[i - 1][j - 1] * a[i];
}
}
lld ans = 0;
for (int i = n / 2 + n % 2; i <= n; i++)
ans += dp[n][i];
cout << setprecision(10) << fixed;
cout << ans;
return 0;
}
/*
5
11000
11100
01100
00000
00000
*/ | replace | 1 | 2 | 1 | 2 | 0 | |
p03168 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <iostream>
#define mp make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
const int MAXN = 3500;
template <typename T> inline T read() {
T res = 0, flag = 1;
char in = getchar();
while (!isdigit(in)) {
if (in == '-')
flag = -1;
in = getchar();
}
while (isdigit(in)) {
res = (res << 1) + (res << 3) + in - '0';
in = getchar();
}
return res * flag;
}
template <typename T> inline void chkmax(T &a, T b) {
if (a < b)
a = b;
}
template <typename T> inline void chkmin(T &a, T b) {
if (a > b)
a = b;
}
double dp[MAXN][MAXN];
double p[MAXN], ans;
int n;
inline void solve() {
n = read<int>();
for (int i = 1; i <= n; ++i)
scanf("%lf", &p[i]);
dp[0][0] = 1;
for (int i = 1; i <= n; ++i)
for (int j = 0; j <= i; ++j) {
dp[i][j] += dp[i - 1][j] * (1 - p[i]);
if (j)
dp[i][j] += dp[i - 1][j - 1] * p[i];
}
for (int i = 1; i <= n; ++i)
if (i > n - i)
ans += dp[n][i];
printf("%.10lf", ans);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("I.in", "r", stdin);
freopen("I.out", "w", stdout);
#endif
solve();
return 0;
}
| #include <algorithm>
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <iostream>
#define mp make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
const int MAXN = 3500;
template <typename T> inline T read() {
T res = 0, flag = 1;
char in = getchar();
while (!isdigit(in)) {
if (in == '-')
flag = -1;
in = getchar();
}
while (isdigit(in)) {
res = (res << 1) + (res << 3) + in - '0';
in = getchar();
}
return res * flag;
}
template <typename T> inline void chkmax(T &a, T b) {
if (a < b)
a = b;
}
template <typename T> inline void chkmin(T &a, T b) {
if (a > b)
a = b;
}
double dp[MAXN][MAXN];
double p[MAXN], ans;
int n;
inline void solve() {
n = read<int>();
for (int i = 1; i <= n; ++i)
scanf("%lf", &p[i]);
dp[0][0] = 1;
for (int i = 1; i <= n; ++i)
for (int j = 0; j <= i; ++j) {
dp[i][j] += dp[i - 1][j] * (1 - p[i]);
if (j)
dp[i][j] += dp[i - 1][j - 1] * p[i];
}
for (int i = 1; i <= n; ++i)
if (i > n - i)
ans += dp[n][i];
printf("%.10lf", ans);
}
int main() {
solve();
return 0;
}
| delete | 61 | 65 | 61 | 61 | TLE | |
p03168 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int n;
ld dp[3005][3005];
ld p[3005];
bool mark[3005][3005];
ld solve(int up, int down) {
if (up + down == n)
return up > down ? 1 : 0;
if (mark[up][down])
return dp[up][down];
ld &ans = dp[up][down];
int idx = up + down;
return ans =
solve(up + 1, down) * p[idx] + solve(up, down + 1) * (1 - p[idx]);
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++)
cin >> p[i];
cout << fixed << setprecision(12) << solve(0, 0);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int n;
ld dp[3005][3005];
ld p[3005];
bool mark[3005][3005];
ld solve(int up, int down) {
if (up + down == n)
return up > down ? 1 : 0;
if (mark[up][down])
return dp[up][down];
mark[up][down] = 1;
ld &ans = dp[up][down];
int idx = up + down;
return ans =
solve(up + 1, down) * p[idx] + solve(up, down + 1) * (1 - p[idx]);
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++)
cin >> p[i];
cout << fixed << setprecision(12) << solve(0, 0);
return 0;
}
| insert | 17 | 17 | 17 | 18 | TLE | |
p03168 | C++ | Runtime Error | #include <iomanip>
#include <iostream>
#include <stdio.h>
using namespace std;
const int maxn = 1e3 + 100;
int n;
double ans;
double a[maxn];
double dp[maxn][maxn];
int main() {
cout << fixed << setprecision(10);
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%lf", &a[i]);
dp[0][0] = 1;
for (int i = 1; i <= n; i++)
for (int j = 0; j <= i; j++) {
if (j > 0)
dp[i][j] += dp[i - 1][j - 1] * a[i];
dp[i][j] += dp[i - 1][j] * (1 - a[i]);
}
for (int i = 0; i <= n; i++)
if (n - i < i)
ans += dp[n][i];
printf("%.12f\n", ans);
return 0;
} | #include <iomanip>
#include <iostream>
#include <stdio.h>
using namespace std;
const int maxn = 3e3 + 100;
int n;
double ans;
double a[maxn];
double dp[maxn][maxn];
int main() {
cout << fixed << setprecision(10);
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%lf", &a[i]);
dp[0][0] = 1;
for (int i = 1; i <= n; i++)
for (int j = 0; j <= i; j++) {
if (j > 0)
dp[i][j] += dp[i - 1][j - 1] * a[i];
dp[i][j] += dp[i - 1][j] * (1 - a[i]);
}
for (int i = 0; i <= n; i++)
if (n - i < i)
ans += dp[n][i];
printf("%.12f\n", ans);
return 0;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p03168 | C++ | Runtime Error |
#include <array>
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define int long long
#define fast_cin \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define endl "\n"
#define endl "\n"
#define with_tests \
int t; \
cin >> t; \
while (t--) { \
solve(); \
cout << endl; \
}
#define without_tests \
solve(); \
cout << endl;
#define CEIL(x, y) (ll) ceil((long double)(x) / (long double)(y))
#define epsilon 1e-9
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 1e3 + 1;
// vector<int> adj[N];
// int vis[N];
// int dp[N];
// int n, u, v;
// // int dp[N][N];
// int dfs(int u){
// if(vis[u] == 1){
// return dp[u];
// }
// vis[u] = 1;
// for(int v: adj[u]){
// dp[u] = max(dp[u], dfs(v)+1);
// }
// return dp[u];
// }
char a[N][N];
double dp[N][N];
double p[N];
void solve() {
int n;
cin >> n;
// vector<double> p(n+1);
for (int i = 1; i <= n; i++) {
cin >> p[i];
// cout
}
dp[1][1] = p[1];
dp[1][0] = 1.0 - p[1];
for (int i = 2; i <= n; i++) {
dp[i][0] = dp[i - 1][0] * (1.0 - p[i]);
for (int j = 1; j <= i; j++) {
dp[i][j] = dp[i - 1][j] * (1.0 - p[i]) + dp[i - 1][j - 1] * p[i];
}
}
double ans = 0.0;
for (int i = (n + 1) / 2; i <= n; i++) {
ans += dp[n][i];
// cout << i << " " << dp[n][i] << endl;
}
cout << fixed << setprecision(12) << ans;
}
int32_t main() {
fast_cin;
// with_tests;
without_tests;
return 0;
}
|
#include <array>
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define int long long
#define fast_cin \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define endl "\n"
#define endl "\n"
#define with_tests \
int t; \
cin >> t; \
while (t--) { \
solve(); \
cout << endl; \
}
#define without_tests \
solve(); \
cout << endl;
#define CEIL(x, y) (ll) ceil((long double)(x) / (long double)(y))
#define epsilon 1e-9
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 3e3 + 1;
// vector<int> adj[N];
// int vis[N];
// int dp[N];
// int n, u, v;
// // int dp[N][N];
// int dfs(int u){
// if(vis[u] == 1){
// return dp[u];
// }
// vis[u] = 1;
// for(int v: adj[u]){
// dp[u] = max(dp[u], dfs(v)+1);
// }
// return dp[u];
// }
char a[N][N];
double dp[N][N];
double p[N];
void solve() {
int n;
cin >> n;
// vector<double> p(n+1);
for (int i = 1; i <= n; i++) {
cin >> p[i];
// cout
}
dp[1][1] = p[1];
dp[1][0] = 1.0 - p[1];
for (int i = 2; i <= n; i++) {
dp[i][0] = dp[i - 1][0] * (1.0 - p[i]);
for (int j = 1; j <= i; j++) {
dp[i][j] = dp[i - 1][j] * (1.0 - p[i]) + dp[i - 1][j - 1] * p[i];
}
}
double ans = 0.0;
for (int i = (n + 1) / 2; i <= n; i++) {
ans += dp[n][i];
// cout << i << " " << dp[n][i] << endl;
}
cout << fixed << setprecision(12) << ans;
}
int32_t main() {
fast_cin;
// with_tests;
without_tests;
return 0;
}
| replace | 27 | 28 | 27 | 28 | 0 | |
p03168 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
double dp[3001][3001];
double solve(vector<double> ar, int i, int x) {
if (x == 0) {
return 1;
}
if (i == 0) {
return 0;
}
if (dp[i][x] > -0.9) {
return dp[i][x];
}
return dp[i][x] = ar[i] * solve(ar, i - 1, x - 1) +
(1 - ar[i]) * solve(ar, i - 1, x);
}
int main() {
int n;
cin >> n;
memset(dp, -1, sizeof dp);
vector<double> ar(n + 1);
for (int i = 1; i <= n; i++) {
cin >> ar[i];
}
cout << fixed << setprecision(10) << solve(ar, n, (n + 1) / 2);
}
| #include <bits/stdc++.h>
using namespace std;
double dp[3001][3001];
double solve(vector<double> &ar, int i, int x) {
if (x == 0) {
return 1;
}
if (i == 0) {
return 0;
}
if (dp[i][x] > -0.9) {
return dp[i][x];
}
return dp[i][x] = ar[i] * solve(ar, i - 1, x - 1) +
(1 - ar[i]) * solve(ar, i - 1, x);
}
int main() {
int n;
cin >> n;
memset(dp, -1, sizeof dp);
vector<double> ar(n + 1);
for (int i = 1; i <= n; i++) {
cin >> ar[i];
}
cout << fixed << setprecision(10) << solve(ar, n, (n + 1) / 2);
}
| replace | 3 | 4 | 3 | 4 | TLE | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int64_t, int64_t> pll;
typedef vector<int64_t> vl;
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
const long double PI = acos(-1);
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i, a, b) for (int64_t i = (a); i < (b); i++)
#define REP(i, n) rep(i, 0, n)
#define sz(s) (s).size()
#define ALL(a) begin(a), end(a)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
vector<vector<double>> dp(3010, vector<double>(1600, 0));
void solve() {
int n;
cin >> n;
dp[0][0] = 1;
double p;
REP(i, n) {
cin >> p;
REP(j, i + 1) {
dp[i + 1][j] += dp[i][j] * p;
dp[i + 1][j + 1] += dp[i][j] * (1 - p);
}
}
p = 0;
REP(i, (n + 1) / 2) p += dp[n][i];
// REP(i,n+1){REP(j,i+1)cout<<dp[i][j]<<" ";cout<<endl;}
cout << fixed << setprecision(10) << p << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int64_t, int64_t> pll;
typedef vector<int64_t> vl;
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
const long double PI = acos(-1);
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i, a, b) for (int64_t i = (a); i < (b); i++)
#define REP(i, n) rep(i, 0, n)
#define sz(s) (s).size()
#define ALL(a) begin(a), end(a)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
double dp[3000][3000];
void solve() {
int n;
cin >> n;
dp[0][0] = 1;
double p;
REP(i, n) {
cin >> p;
REP(j, i + 1) {
dp[i + 1][j] += dp[i][j] * p;
dp[i + 1][j + 1] += dp[i][j] * (1 - p);
}
}
p = 0;
REP(i, (n + 1) / 2) p += dp[n][i];
// REP(i,n+1){REP(j,i+1)cout<<dp[i][j]<<" ";cout<<endl;}
cout << fixed << setprecision(10) << p << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
}
| replace | 22 | 23 | 22 | 23 | 0 | |
p03168 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
int n;
double dp[3000][3000];
vector<double> v;
double calc(int idx, int sum) {
if (idx == n) {
if (sum > n / 2)
return 1.0;
return 0.0;
}
double &ret = dp[idx][sum];
if (ret < 0)
return ret;
ret = v[idx] * calc(idx + 1, sum + 1) + (1 - v[idx]) * calc(idx + 1, sum);
return ret;
}
int main() {
// freopen("src.txt", "r", stdin);
memset(dp, -1, sizeof dp);
cin >> n;
v.resize(n);
for (int i = 0; i < n; ++i)
cin >> v[i];
printf("%.15f\n", v[0] * calc(1, 1) + (1 - v[0]) * calc(1, 0));
return 0;
} | #include <algorithm>
#include <bitset>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
int n;
double dp[3000][3000];
vector<double> v;
double calc(int idx, int sum) {
if (idx == n) {
if (sum > n / 2)
return 1.0;
return 0.0;
}
double &ret = dp[idx][sum];
if (ret > -1)
return ret;
ret = v[idx] * calc(idx + 1, sum + 1) + (1 - v[idx]) * calc(idx + 1, sum);
return ret;
}
int main() {
// freopen("src.txt", "r", stdin);
memset(dp, -1, sizeof dp);
cin >> n;
v.resize(n);
for (int i = 0; i < n; ++i)
cin >> v[i];
printf("%.15f\n", v[0] * calc(1, 1) + (1 - v[0]) * calc(1, 0));
return 0;
} | replace | 30 | 31 | 30 | 31 | TLE | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
#define pb push_back
#define rep(a, b, c) for (int a = (int)b; a < (int)c; a++)
#define repe(a, b, c) for (int a = (int)b; a <= (int)c; a++)
#define repk(a, b, c, k) for (int a = (int)b; a < (int)c; a += (int)k)
#define comeback \
std::ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define mod 1000000007
#define int long long int
#define pii pair<int, int>
#define ful(a) a.begin(), a.end()
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
using namespace std;
int em(int x, int n) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return em((x % mod * x % mod) % mod, n / 2);
else
return (x % mod * em((x % mod * x % mod) % mod, (n - 1) / 2)) % mod;
}
double dp[1009][1009];
signed main() {
comeback
/*#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output1.txt","w",stdout);
#endif*/
int n,
m, i, j, k, l;
cin >> n;
double pr[n + 1];
repe(i, 1, n) cin >> pr[i];
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
repe(i, 1, n) {
repe(j, 0, i) {
if (j - 1 >= 0)
dp[i][j] = (dp[i - 1][j - 1] * (1 - pr[i]) + dp[i - 1][j] * pr[i]);
else
dp[i][j] = dp[i - 1][j] * pr[i];
}
}
double ans = 0;
repe(i, 0, n / 2) ans += dp[n][i];
cout << fixed << setprecision(9) << ans;
} | #include <bits/stdc++.h>
#define pb push_back
#define rep(a, b, c) for (int a = (int)b; a < (int)c; a++)
#define repe(a, b, c) for (int a = (int)b; a <= (int)c; a++)
#define repk(a, b, c, k) for (int a = (int)b; a < (int)c; a += (int)k)
#define comeback \
std::ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define mod 1000000007
#define int long long int
#define pii pair<int, int>
#define ful(a) a.begin(), a.end()
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
using namespace std;
int em(int x, int n) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return em((x % mod * x % mod) % mod, n / 2);
else
return (x % mod * em((x % mod * x % mod) % mod, (n - 1) / 2)) % mod;
}
double dp[3009][3009];
signed main() {
comeback
/*#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output1.txt","w",stdout);
#endif*/
int n,
m, i, j, k, l;
cin >> n;
double pr[n + 1];
repe(i, 1, n) cin >> pr[i];
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
repe(i, 1, n) {
repe(j, 0, i) {
if (j - 1 >= 0)
dp[i][j] = (dp[i - 1][j - 1] * (1 - pr[i]) + dp[i - 1][j] * pr[i]);
else
dp[i][j] = dp[i - 1][j] * pr[i];
}
}
double ans = 0;
repe(i, 0, n / 2) ans += dp[n][i];
cout << fixed << setprecision(9) << ans;
} | replace | 26 | 27 | 26 | 27 | 0 | |
p03168 | C++ | Runtime Error |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
/*
||||||||||||||||||||||||||||||||||||||||||||||||
| ||| | |||| |||| | |
| | | | | | | | | | |
| | | | | | | | | | |
||||||| | | ||||||| ||| ||| |||||
| | | | | | | | | | |
| | ||| | | | || |||| | |
||||||||||||||||||||||||||||||||||||||||||||||||
*/
using namespace std;
// #include "testlib.h"
#define ff first
#define ss second
#define mp make_pair
#define all(v) v.begin(), v.end()
#define int long long
#define ll long long
#define M 1000000007
#define inputarr(a, n) \
for (int i = 0; i < n; ++i) \
cin >> a[i]
#define GCD(m, n) __gcd(m, n)
#define LCM(m, n) m *(n / GCD(m, n))
#define mii map<ll, ll>
#define msi map<string, ll>
#define mis map<ll int, string>
#define rep(a, b) for (ll i = a; i < b; i++)
#define rep0(n) for (ll i = 0; i < n; i++)
#define repi(i, a, b) for (ll i = a; i < b; i++)
#define pb push_back
#define vi vector<ll>
#define mp make_pair
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); --i)
#define FORE(it, c) \
for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define inputoutput \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
#define input freopen("input.txt", "r", stdin);
#define Set(a, s) 4(a, s, sizeof(a))
#define FOR repi
#define pii pair<int, int>
#define REVERSE(v) reverse(ALL(v))
#define display(x) \
trav(a, x) cout << a << " "; \
cout << endl
#define debug cerr << "bhau" << endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
std::cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
// #define float long double
ll max(ll a, ll b) { return (a > b) ? a : b; }
int min(int a, int b) { return (a < b) ? a : b; }
#define float double
int solve() {
int n;
cin >> n;
vector<float> p(n);
inputarr(p, n);
float dp[n + 1][n + 1];
dp[0][0] = 1;
rep(1, n + 1) {
dp[i][0] = dp[i - 1][0] * (1 - p[i - 1]);
repi(j, 1, n + 1) {
if (j > i) {
dp[i][j] = 0;
continue;
}
dp[i][j] = dp[i - 1][j] * (1 - p[i - 1]);
dp[i][j] += dp[i - 1][j - 1] * p[i - 1];
}
}
// rep0(n+1){repi(j,0,n+1) cout<<dp[j][i]<<" ";cout<<endl;}
int mi = n / 2;
float ans = 0;
for (int i = mi + 1; i <= n; i++)
// cout<<dp[n][i]<<" ";//
ans += dp[n][i];
cout << fixed << setprecision(10) << ans;
r0
}
signed main() {
asdf inputoutput int t = 1;
// cin>>t;
while (t--) {
solve();
}
} |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
/*
||||||||||||||||||||||||||||||||||||||||||||||||
| ||| | |||| |||| | |
| | | | | | | | | | |
| | | | | | | | | | |
||||||| | | ||||||| ||| ||| |||||
| | | | | | | | | | |
| | ||| | | | || |||| | |
||||||||||||||||||||||||||||||||||||||||||||||||
*/
using namespace std;
// #include "testlib.h"
#define ff first
#define ss second
#define mp make_pair
#define all(v) v.begin(), v.end()
#define int long long
#define ll long long
#define M 1000000007
#define inputarr(a, n) \
for (int i = 0; i < n; ++i) \
cin >> a[i]
#define GCD(m, n) __gcd(m, n)
#define LCM(m, n) m *(n / GCD(m, n))
#define mii map<ll, ll>
#define msi map<string, ll>
#define mis map<ll int, string>
#define rep(a, b) for (ll i = a; i < b; i++)
#define rep0(n) for (ll i = 0; i < n; i++)
#define repi(i, a, b) for (ll i = a; i < b; i++)
#define pb push_back
#define vi vector<ll>
#define mp make_pair
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); --i)
#define FORE(it, c) \
for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define inputoutput \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
#define input freopen("input.txt", "r", stdin);
#define Set(a, s) 4(a, s, sizeof(a))
#define FOR repi
#define pii pair<int, int>
#define REVERSE(v) reverse(ALL(v))
#define display(x) \
trav(a, x) cout << a << " "; \
cout << endl
#define debug cerr << "bhau" << endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
std::cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
// #define float long double
ll max(ll a, ll b) { return (a > b) ? a : b; }
int min(int a, int b) { return (a < b) ? a : b; }
#define float double
int solve() {
int n;
cin >> n;
vector<float> p(n);
inputarr(p, n);
float dp[n + 1][n + 1];
dp[0][0] = 1;
rep(1, n + 1) {
dp[i][0] = dp[i - 1][0] * (1 - p[i - 1]);
repi(j, 1, n + 1) {
if (j > i) {
dp[i][j] = 0;
continue;
}
dp[i][j] = dp[i - 1][j] * (1 - p[i - 1]);
dp[i][j] += dp[i - 1][j - 1] * p[i - 1];
}
}
// rep0(n+1){repi(j,0,n+1) cout<<dp[j][i]<<" ";cout<<endl;}
int mi = n / 2;
float ans = 0;
for (int i = mi + 1; i <= n; i++)
// cout<<dp[n][i]<<" ";//
ans += dp[n][i];
cout << fixed << setprecision(10) << ans;
r0
}
signed main() {
asdf
// inputoutput
int t = 1;
// cin>>t;
while (t--) {
solve();
}
} | replace | 108 | 109 | 108 | 111 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03168 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define pr_double(x) cout << fixed << setprecision(10) << x;
double dp[3001][3001];
double solve(vector<double> &ar, int i, int x) {
if (x == 0) {
return 1;
} else if (i == 0) {
return 0;
}
if (dp[i][x] > 0.9) {
return dp[i][x];
}
return dp[i][x] = ar[i] * solve(ar, i - 1, x - 1) +
(1 - ar[i]) * solve(ar, i - 1, x);
}
int main() {
int n;
cin >> n;
memset(dp, -1, sizeof dp);
vector<double> ar(n + 1);
for (int i = 1; i < n + 1; i++) {
cin >> ar[i];
}
pr_double(solve(ar, n, (n + 1) / 2));
} | #include <bits/stdc++.h>
using namespace std;
#define pr_double(x) cout << fixed << setprecision(10) << x;
double dp[3001][3001];
double solve(vector<double> &ar, int i, int x) {
if (x == 0) {
return 1;
} else if (i == 0) {
return 0;
}
if (dp[i][x] > -0.9) {
return dp[i][x];
}
return dp[i][x] = ar[i] * solve(ar, i - 1, x - 1) +
(1 - ar[i]) * solve(ar, i - 1, x);
}
int main() {
int n;
cin >> n;
memset(dp, -1, sizeof dp);
vector<double> ar(n + 1);
for (int i = 1; i < n + 1; i++) {
cin >> ar[i];
}
pr_double(solve(ar, n, (n + 1) / 2));
} | replace | 14 | 15 | 14 | 15 | TLE | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
const int MAXN = 300 + 5;
using namespace std;
int n;
long double dp[MAXN][MAXN], probability[MAXN];
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> probability[i];
dp[0][0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
dp[i + 1][j] += dp[i][j] * (1 - probability[i + 1]);
dp[i + 1][j + 1] += dp[i][j] * probability[i + 1];
}
}
long double ans = 0;
for (int j = n / 2 + 1; j <= n; j++)
ans += dp[n][j];
cout << setprecision(10) << fixed << ans;
return 0;
} | #include <bits/stdc++.h>
const int MAXN = 3000 + 5;
using namespace std;
int n;
long double dp[MAXN][MAXN], probability[MAXN];
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> probability[i];
dp[0][0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
dp[i + 1][j] += dp[i][j] * (1 - probability[i + 1]);
dp[i + 1][j + 1] += dp[i][j] * probability[i + 1];
}
}
long double ans = 0;
for (int j = n / 2 + 1; j <= n; j++)
ans += dp[n][j];
cout << setprecision(10) << fixed << ans;
return 0;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p03168 | Python | Time Limit Exceeded | N = int(input())
P = list(map(float, input().split()))
dp = [0] * (N + 1)
dp[0] = 1
for i in range(1, N + 1):
tmp = dp
dp = [0] * (N + 1)
for j in range(N):
if j < N:
dp[j + 1] += tmp[j] * P[i - 1]
dp[j] += tmp[j] * (1 - P[i - 1])
num = 0
for i in range(N // 2 + 1, N + 1):
num += dp[i]
print(num)
| N = int(input())
P = list(map(float, input().split()))
# dp = [[0] * (N + 1) for i in range(N + 1)]
# dp[0][0] = 1.0
# for i in range(1, N + 1):
# for j in range(N):
# if j < N:
# dp[i][j + 1] += dp[i - 1][j] * P[i - 1]
# dp[i][j] += dp[i - 1][j] * (1 - P[i - 1])
#
# num = 0
# for i in range(N // 2 + 1, N + 1):
# num += dp[N][i]
#
# print(num)
dp = [0] * (N + 1)
dp[0] = 1
for i in range(1, N + 1):
tmp = dp
dp = [0] * (N + 1)
for j in range(N):
if j < N:
dp[j + 1] += tmp[j] * P[i - 1]
dp[j] += tmp[j] * (1 - P[i - 1])
num = 0
for i in range(N // 2 + 1, N + 1):
num += dp[i]
print(num)
| insert | 2 | 2 | 2 | 16 | TLE | |
p03168 | Python | Time Limit Exceeded | # -*- coding: utf-8 -*-
# from collections import deque
from sys import setrecursionlimit
setrecursionlimit(1000000)
# INF = float("inf")
# d = deque()
# ---Input---#
n = int(input())
# n, k = map(int, input().split())
p = list(map(float, input().split()))
p = [-1] + p
memo = [[-1 for _ in [0] * (n + 1)] for _ in [0] * (n + 1)]
memo[0][0] = 1
for i in range(len(p))[1:]:
memo[0][i] = 0
memo[i][0] = memo[i - 1][0] * (1 - p[i])
memo[0][0] = 1
def dp(i, j):
if memo[i][j] == -1:
memo[i][j] = dp(i - 1, j) * (1 - p[i]) + dp(i - 1, j - 1) * p[i]
return memo[i][j]
ans = 0
tar = int(n / 2) + 1
for i in range(n + 1)[tar:]:
ans += dp(n, i)
print("{}".format(ans))
| # -*- coding: utf-8 -*-
# from collections import deque
from sys import setrecursionlimit
setrecursionlimit(1000000)
# INF = float("inf")
# d = deque()
# ---Input---#
n = int(input())
# n, k = map(int, input().split())
p = list(map(float, input().split()))
p = [-1] + p
memo = [[-1 for _ in [0] * (n + 1)] for _ in [0] * (n + 1)]
memo[0][0] = 1
for i in range(len(p))[1:]:
memo[0][i] = 0
memo[i][0] = memo[i - 1][0] * (1 - p[i])
memo[0][0] = 1
def dp(i, j):
if memo[i][j] == -1:
memo[i][j] = dp(i - 1, j) * (1 - p[i]) + dp(i - 1, j - 1) * p[i]
return memo[i][j]
ans = 0
tar = int(n / 2) + 1
for i in range(n + 1):
dp(i, i)
dp(i, n)
for i in range(n + 1)[tar:]:
ans += dp(n, i)
print("{}".format(ans))
| insert | 32 | 32 | 32 | 36 | TLE | |
p03168 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
const double EPS = 1e-11;
const double PI = 2 * acos(0.0);
using ll = long long;
using ull = unsigned long long;
#define input freopen("input.txt", "r", stdin)
#define output freopen("output.txt", "w", stdout)
#define fast_io \
ios_base::sync_with_stdio(0); \
cin.tie(nullptr); \
cout.tie(nullptr);
#define pf printf
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define sii(x, y) scanf("%d %d", &x, &y)
#define sll(x, y) scanf("%lld %lld", &x, &y)
#define pii pair<int, int>
#define nl '\n'
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define uniq(a) a.erase(unique(a.begin(), a.end()), a.end())
#define out(x) cout << "#x = " << x << endl
#define outt(x, y) cout << "# " << x << " " << y << endl
#define mem(array, value) memset(array, value, sizeof(array))
const int MX = 1e3 + 2;
double coin[MX];
double dp[MX][MX];
int n;
double solve(int i, int head) {
if (i == n) {
if (head > n / 2)
return 1;
else
return 0;
}
if (dp[i][head] != -1.0)
return dp[i][head];
double a =
(coin[i] * solve(i + 1, head + 1)) + ((1 - coin[i]) * solve(i + 1, head));
return dp[i][head] = a;
}
int main() {
fast_io
for (int i = 0; i < MX; i++) {
for (int j = 0; j < MX; j++) {
dp[i][j] = -1.0;
}
}
// int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> coin[i];
}
double ans = solve(0, 0);
pf("%.10lf\n", ans);
}
| #include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
const double EPS = 1e-11;
const double PI = 2 * acos(0.0);
using ll = long long;
using ull = unsigned long long;
#define input freopen("input.txt", "r", stdin)
#define output freopen("output.txt", "w", stdout)
#define fast_io \
ios_base::sync_with_stdio(0); \
cin.tie(nullptr); \
cout.tie(nullptr);
#define pf printf
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define sii(x, y) scanf("%d %d", &x, &y)
#define sll(x, y) scanf("%lld %lld", &x, &y)
#define pii pair<int, int>
#define nl '\n'
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define uniq(a) a.erase(unique(a.begin(), a.end()), a.end())
#define out(x) cout << "#x = " << x << endl
#define outt(x, y) cout << "# " << x << " " << y << endl
#define mem(array, value) memset(array, value, sizeof(array))
const int MX = 3e3 + 2;
double coin[MX];
double dp[MX][MX];
int n;
double solve(int i, int head) {
if (i == n) {
if (head > n / 2)
return 1;
else
return 0;
}
if (dp[i][head] != -1.0)
return dp[i][head];
double a =
(coin[i] * solve(i + 1, head + 1)) + ((1 - coin[i]) * solve(i + 1, head));
return dp[i][head] = a;
}
int main() {
fast_io
for (int i = 0; i < MX; i++) {
for (int j = 0; j < MX; j++) {
dp[i][j] = -1.0;
}
}
// int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> coin[i];
}
double ans = solve(0, 0);
pf("%.10lf\n", ans);
}
| replace | 32 | 33 | 32 | 33 | 0 | |
p03168 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
using namespace std;
double dp[3001][3001];
double calc_prob(int n, vector<double> pH, ll HC, vector<vector<double>> &dp) {
if (HC == 0) {
return 1;
}
if (n < 0) {
return 0;
}
if (dp[n][HC] > -0.9) {
return dp[n][HC];
}
double ans = pH[n] * calc_prob(n - 1, pH, HC - 1, dp) +
(1 - pH[n]) * calc_prob(n - 1, pH, HC, dp);
return dp[n][HC] = ans;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll n;
cin >> n;
vector<double> pH(n);
for (int i = 0; i < n; i++) {
double f;
cin >> f;
pH[i] = f;
}
// for (int i = 0; i < n; i++)
// {
// for (int j = 0; j < (n + 1) / 2; j++)
// {
// cout << dp[i][j] << " ";
// }
// cout << endl;
// }
vector<vector<double>> dp(n + 1, vector<double>((n + 1) / 2 + 1, -1));
cout << fixed << setprecision(10) << calc_prob(n - 1, pH, (n + 1) / 2, dp)
<< endl;
return 0;
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
double dp[3001][3001];
double calc_prob(int n, vector<double> &pH, ll HC, vector<vector<double>> &dp) {
if (HC == 0) {
return 1;
}
if (n < 0) {
return 0;
}
if (dp[n][HC] > -0.9) {
return dp[n][HC];
}
double ans = pH[n] * calc_prob(n - 1, pH, HC - 1, dp) +
(1 - pH[n]) * calc_prob(n - 1, pH, HC, dp);
return dp[n][HC] = ans;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll n;
cin >> n;
vector<double> pH(n);
for (int i = 0; i < n; i++) {
double f;
cin >> f;
pH[i] = f;
}
// for (int i = 0; i < n; i++)
// {
// for (int j = 0; j < (n + 1) / 2; j++)
// {
// cout << dp[i][j] << " ";
// }
// cout << endl;
// }
vector<vector<double>> dp(n + 1, vector<double>((n + 1) / 2 + 1, -1));
cout << fixed << setprecision(10) << calc_prob(n - 1, pH, (n + 1) / 2, dp)
<< endl;
return 0;
} | replace | 4 | 5 | 4 | 5 | TLE | |
p03168 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
using namespace std;
double dp[3001][3001];
double calc_prob(int n, vector<double> pH, ll HC) {
if (HC == 0) {
return 1;
}
if (n < 0) {
return 0;
}
if (dp[n][HC] > -0.9) {
return dp[n][HC];
}
double ans = pH[n] * calc_prob(n - 1, pH, HC - 1) +
(1 - pH[n]) * calc_prob(n - 1, pH, HC);
return dp[n][HC] = ans;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll n;
cin >> n;
vector<double> pH(n);
for (int i = 0; i < n; i++) {
double f;
cin >> f;
pH[i] = f;
}
// for (int i = 0; i < n; i++)
// {
// for (int j = 0; j < (n + 1) / 2; j++)
// {
// cout << dp[i][j] << " ";
// }
// cout << endl;
// }
memset(dp, -1, sizeof(dp));
cout << fixed << setprecision(10) << calc_prob(n - 1, pH, (n + 1) / 2);
return 0;
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
double dp[3001][3001];
double calc_prob(int n, vector<double> &pH, ll HC) {
if (HC == 0) {
return 1;
}
if (n < 0) {
return 0;
}
if (dp[n][HC] > -0.9) {
return dp[n][HC];
}
double ans = pH[n] * calc_prob(n - 1, pH, HC - 1) +
(1 - pH[n]) * calc_prob(n - 1, pH, HC);
return dp[n][HC] = ans;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll n;
cin >> n;
vector<double> pH(n);
for (int i = 0; i < n; i++) {
double f;
cin >> f;
pH[i] = f;
}
// for (int i = 0; i < n; i++)
// {
// for (int j = 0; j < (n + 1) / 2; j++)
// {
// cout << dp[i][j] << " ";
// }
// cout << endl;
// }
memset(dp, -1, sizeof(dp));
cout << fixed << setprecision(10) << calc_prob(n - 1, pH, (n + 1) / 2);
return 0;
} | replace | 4 | 5 | 4 | 5 | TLE | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define M 1000000007
using namespace std;
ld dp[3001][3001];
ld f(vector<ld> &a, int i, int x) {
if (x == 0)
return 1;
if (i == 0)
return 0;
if (dp[i][x] > -0.9)
return dp[i][x];
return dp[i][x] = a[i] * f(a, i - 1, x - 1) + (1 - a[i]) * f(a, i - 1, x);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
memset(dp, -1, sizeof(dp));
vector<ld> a(n + 1);
for (int i = 1; i <= n; i++)
cin >> a[i];
cout << fixed << setprecision(10) << f(a, n, (n + 1) / 2);
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define M 1000000007
using namespace std;
ld dp[3001][3001];
ld f(vector<ld> &a, int i, int x) {
if (x == 0)
return 1;
if (i == 0)
return 0;
if (dp[i][x] > -0.9)
return dp[i][x];
return dp[i][x] = a[i] * f(a, i - 1, x - 1) + (1 - a[i]) * f(a, i - 1, x);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int n;
cin >> n;
memset(dp, -1, sizeof(dp));
vector<ld> a(n + 1);
for (int i = 1; i <= n; i++)
cin >> a[i];
cout << fixed << setprecision(10) << f(a, n, (n + 1) / 2);
return 0;
} | replace | 23 | 27 | 23 | 27 | -11 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ld long double
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define endl '\n'
const int mod = 1e9 + 7, u = 1e3 + 5;
ld dp[u][u];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
ld p[n + 1];
for (int i = 1; i <= n; i++) {
cin >> p[i];
}
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
dp[i][0] = dp[i - 1][0] * (1 - p[i]);
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
dp[i][j] = (dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]));
}
}
ld ans = 0;
for (int i = n / 2 + 1; i <= n; i++) {
ans += dp[n][i];
}
cout << fixed << setprecision(10) << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ld long double
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define endl '\n'
const int mod = 1e9 + 7, u = 3e3 + 5;
ld dp[u][u];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
ld p[n + 1];
for (int i = 1; i <= n; i++) {
cin >> p[i];
}
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
dp[i][0] = dp[i - 1][0] * (1 - p[i]);
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
dp[i][j] = (dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]));
}
}
ld ans = 0;
for (int i = n / 2 + 1; i <= n; i++) {
ans += dp[n][i];
}
cout << fixed << setprecision(10) << ans;
return 0;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set \
tree<int, null_type, less_equal<int>, rb_tree_tag, \
tree_order_statistics_node_update>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(c) c.begin(), c.end()
#define llv vector<ll>
#define mp make_pair
#define endl "\n"
const int N = (int)1e5 + 10;
const int M = (int)1000000007;
int main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, i, j;
cin >> n;
double p[n + 1];
for (i = 1; i <= n; i++) {
cin >> p[i];
}
double dp[n + 1][n + 1];
fill(&dp[0][0], &dp[0][0] + sizeof(dp), 0.0);
dp[0][0] = 1.0;
for (i = 1; i <= n; i++) {
dp[i][0] = dp[i - 1][0] * (1.0 - p[i]);
for (j = 1; j <= i; j++) {
dp[i][j] = p[i] * dp[i - 1][j - 1] + (1.0 - p[i]) * dp[i - 1][j];
}
}
double ans = 0.0;
for (i = (n + 1) / 2; i <= n; i++) {
ans += dp[n][i];
}
cout << setprecision(10) << fixed << ans;
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set \
tree<int, null_type, less_equal<int>, rb_tree_tag, \
tree_order_statistics_node_update>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(c) c.begin(), c.end()
#define llv vector<ll>
#define mp make_pair
#define endl "\n"
const int N = (int)1e5 + 10;
const int M = (int)1000000007;
int main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, i, j;
cin >> n;
double p[n + 1];
for (i = 1; i <= n; i++) {
cin >> p[i];
}
double dp[n + 1][n + 1];
for (i = 0; i <= n; i++) {
for (j = 0; j <= n; j++) {
dp[i][j] = 0.0;
}
}
dp[0][0] = 1.0;
for (i = 1; i <= n; i++) {
dp[i][0] = dp[i - 1][0] * (1.0 - p[i]);
for (j = 1; j <= i; j++) {
dp[i][j] = p[i] * dp[i - 1][j - 1] + (1.0 - p[i]) * dp[i - 1][j];
}
}
double ans = 0.0;
for (i = (n + 1) / 2; i <= n; i++) {
ans += dp[n][i];
}
cout << setprecision(10) << fixed << ans;
return 0;
} | replace | 35 | 36 | 35 | 40 | -11 | |
p03168 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 3001, mod = 1e9 + 7;
double p[N];
double dp[N][N];
int n;
double dfs(int pos, int k) {
if (pos == n + 1) {
return k == 0 ? 1.0 : 0.0;
}
double &ret = dp[pos][k];
if (ret > 0)
return ret;
ret = 0.0;
ret = p[pos] * dfs(pos + 1, k - 1);
ret += (1.0 - p[pos]) * dfs(pos + 1, k);
return ret;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i += 1)
cin >> p[i];
for (int i = 0; i <= n; i += 1)
for (int j = 0; j <= n; j += 1)
dp[i][j] = -1.0;
double ans = 0.0;
for (int i = n / 2 + 1; i <= n; i += 1)
ans += dfs(1, i);
cout << setprecision(10) << fixed << ans << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 3001, mod = 1e9 + 7;
double p[N];
double dp[N][N];
int n;
double dfs(int pos, int k) {
if (pos == n + 1) {
return k == 0 ? 1.0 : 0.0;
}
double &ret = dp[pos][k];
if (ret != -1.0)
return ret;
ret = 0.0;
ret = p[pos] * dfs(pos + 1, k - 1);
ret += (1.0 - p[pos]) * dfs(pos + 1, k);
return ret;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i += 1)
cin >> p[i];
for (int i = 0; i <= n; i += 1)
for (int j = 0; j <= n; j += 1)
dp[i][j] = -1.0;
double ans = 0.0;
for (int i = n / 2 + 1; i <= n; i += 1)
ans += dfs(1, i);
cout << setprecision(10) << fixed << ans << '\n';
return 0;
}
| replace | 15 | 16 | 15 | 16 | TLE | |
p03168 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;
using ll = long long;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline void dump(vector<T> v) {
for (auto &x : v)
cerr << x << " ";
cerr << endl;
}
template <class T> inline void dump(vector<pair<T, T>> v) {
for (auto &p : v)
cerr << p.first << " " << p.second << endl;
}
template <class T> inline void dump(vector<vector<T>> vv) {
for (auto &v : vv) {
for (auto &x : v)
cerr << x << " ";
cerr << endl;
}
}
constexpr int INF = 1e9 + 5;
constexpr long long INFLL = 1LL << 60;
constexpr double eps = (1e-9);
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<double> p(n + 1, 0);
rep(i, n) cin >> p[i + 1];
vector<vector<double>> dp(
n + 1, vector<double>(n + 1, 0)); // i 枚投げて表が j 枚出る確率
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= i; j++) {
if (j > 0)
dp[i][j] = dp[i - 1][j] * (1 - p[i]) + dp[i - 1][j - 1] * p[i];
else
dp[i][j] = dp[i - 1][j] * (1 - p[i]);
}
}
double ans = 0;
for (int j = n / 2 + 1; j <= n; j++)
ans += dp[n][j];
dump(dp);
printf("%.10f\n", ans);
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;
using ll = long long;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline void dump(vector<T> v) {
for (auto &x : v)
cerr << x << " ";
cerr << endl;
}
template <class T> inline void dump(vector<pair<T, T>> v) {
for (auto &p : v)
cerr << p.first << " " << p.second << endl;
}
template <class T> inline void dump(vector<vector<T>> vv) {
for (auto &v : vv) {
for (auto &x : v)
cerr << x << " ";
cerr << endl;
}
}
constexpr int INF = 1e9 + 5;
constexpr long long INFLL = 1LL << 60;
constexpr double eps = (1e-9);
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<double> p(n + 1, 0);
rep(i, n) cin >> p[i + 1];
vector<vector<double>> dp(
n + 1, vector<double>(n + 1, 0)); // i 枚投げて表が j 枚出る確率
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= i; j++) {
if (j > 0)
dp[i][j] = dp[i - 1][j] * (1 - p[i]) + dp[i - 1][j - 1] * p[i];
else
dp[i][j] = dp[i - 1][j] * (1 - p[i]);
}
}
double ans = 0;
for (int j = n / 2 + 1; j <= n; j++)
ans += dp[n][j];
printf("%.10f\n", ans);
return 0;
}
| delete | 72 | 74 | 72 | 72 | TLE | |
p03168 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define pi 3.1415926535
#include <chrono>
#define MOD 1000000007
#define INF 999999999999999999
#define pb push_back
#define ff first
#define ss second
#define mt make_tuple
#define ll long long
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define f0 get<0>(temp)
#define f1 get<1>(temp)
#define f2 get<2>(temp)
using namespace std;
ll n;
ll ncr(ll n, ll r) {
ll i, ans = 1, k = 0;
if (r == 0)
return 1;
else if (n < r)
return 0;
for (i = n; i >= n - r + 1; i--) {
ans *= i;
ans /= n - i + 1;
}
return ans;
}
void max_heapify(int a[100], int i) {
int l, r, largest = i;
l = 2 * i + 1;
r = 2 * i + 2;
if (l < n && a[l] > a[i])
largest = l;
if (r < n && a[r] > a[l])
largest = r;
if (largest != i) {
int k;
k = a[i];
a[i] = a[largest];
a[largest] = k;
max_heapify(a, largest);
}
}
int power(ll x, ll y, ll p) {
int res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
bool square(ll n) {
double x;
x = sqrt(n);
if (x == floor(x))
return true;
else
return false;
}
bool prime(ll n) {
ll i;
for (i = 2; i * i <= n; i++) {
if (n % i == 0)
return false;
}
return true;
}
ll modi(ll a, ll m) { return power(a, m - 2, m); }
void kmp(string s, ll p[]) {
int n = (int)s.length();
p[0] = 0;
for (int i = 1; i < n; i++) {
int j = p[i - 1];
while (j > 0 && s[i] != s[j])
j = p[j - 1];
if (s[i] == s[j])
j++;
p[i] = j;
}
}
void zfunc(string s, ll z[]) {
ll n = (ll)s.length();
z[0] = 0;
for (ll i = 1, l = 0, r = 0; i < n; ++i) {
if (i <= r)
z[i] = min(r - i + 1, z[i - l]);
while (i + z[i] < n && s[z[i]] == s[i + z[i]])
++z[i];
if (i + z[i] - 1 > r)
l = i, r = i + z[i] - 1;
}
}
struct pair_hash {
size_t operator()(const pair<int, int> &p) const noexcept {
return hash<ll>()((((ll)p.first) << 32) | ((ll)p.second));
}
};
bool palin(string s) {
ll i, n;
n = s.length();
for (i = 0; i <= n / 2; i++) {
if (s[i] != s[n - i - 1]) {
return false;
}
}
return true;
}
ll sum(ll n) {
ll i;
i = n;
ll sum = 0;
while (i > 0) {
sum += i % 10;
i = i / 10;
}
return sum;
}
ll nCr(ll n, ll r, ll p, ll fac[]) {
if (r == 0)
return 1;
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = fac[i - 1] * i % p;
return (fac[n] * modi(fac[r], p) % p * modi(fac[n - r], p) % p) % p;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
void bfs(vector<ll> &ans, ll k) {
queue<ll> q;
while (!q.empty()) {
ll temp = q.front();
}
}
void solve(ll l, ll r) {
if (l >= r) {
return;
}
if ((r - l) % 2 == 1) {
ll start = (r + l) / 2 + 1;
ll k = -1, j = 1;
while (start != l) {
printf("%lld %lld\n", start, start + k * j);
// cout <<start <<" "<< start + k * j << endl;
if (start + k * j == l) {
break;
}
start += k * j;
j++;
k *= -1;
}
} else {
ll start = (r + l) / 2;
ll k = 1, j = 1;
while (start != l) {
printf("%lld %lld\n", start, start + k * j);
// cout << start << " " << start + k * j << endl;
if (start + k * j == l) {
break;
}
start += k * j;
j++;
k *= -1;
}
}
}
void dfs(ll start, vector<ll> adj[], bool visited[], ll dp[], ll &maxi) {
visited[start] = true;
for (auto u : adj[start]) {
if (!visited[u]) {
visited[u] = true;
dp[u] = max(dp[u], dp[start] + 1);
dfs(u, adj, visited, dp, maxi);
maxi = max(maxi, dp[u]);
}
}
}
float fab(float x) {
if (x < 0) {
return -x;
}
return x;
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ll T = 1, i, j;
// cin >> T;
while (T--) {
ll n;
cin >> n;
vector<double> v(n);
ll maxtails = (n - 1) / 2;
for (i = 0; i < n; i++) {
cin >> v[i];
}
double dp[100][100];
for (i = 0; i <= n; i++) {
for (j = 0; j <= maxtails; j++) {
dp[i][j] = 0;
}
}
for (i = 0; i <= maxtails; i++) {
dp[0][i] = 1.0;
}
dp[1][0] = v[0];
dp[1][1] = 1 - v[0];
for (i = 1; i < n; i++) {
for (j = 0; j <= maxtails; j++) {
dp[i + 1][j] += dp[i][j] * v[i];
dp[i + 1][j + 1] += dp[i][j] * (1 - v[i]);
}
}
double ans = 0;
// for (i = 1; i <= n; i++) {
// for (j = 0; j <= maxtails; j++) {
// cout << dp[i][j] << " ";
// }
// cout << endl;
// }
for (i = 0; i <= maxtails; i++) {
ans += dp[n][i];
// cout << dp[n][i] << endl;
}
cout << fixed << setprecision(10) << ans << endl;
}
return 0;
}
| #include <algorithm>
#include <bitset>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define pi 3.1415926535
#include <chrono>
#define MOD 1000000007
#define INF 999999999999999999
#define pb push_back
#define ff first
#define ss second
#define mt make_tuple
#define ll long long
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define f0 get<0>(temp)
#define f1 get<1>(temp)
#define f2 get<2>(temp)
using namespace std;
ll n;
ll ncr(ll n, ll r) {
ll i, ans = 1, k = 0;
if (r == 0)
return 1;
else if (n < r)
return 0;
for (i = n; i >= n - r + 1; i--) {
ans *= i;
ans /= n - i + 1;
}
return ans;
}
void max_heapify(int a[100], int i) {
int l, r, largest = i;
l = 2 * i + 1;
r = 2 * i + 2;
if (l < n && a[l] > a[i])
largest = l;
if (r < n && a[r] > a[l])
largest = r;
if (largest != i) {
int k;
k = a[i];
a[i] = a[largest];
a[largest] = k;
max_heapify(a, largest);
}
}
int power(ll x, ll y, ll p) {
int res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
bool square(ll n) {
double x;
x = sqrt(n);
if (x == floor(x))
return true;
else
return false;
}
bool prime(ll n) {
ll i;
for (i = 2; i * i <= n; i++) {
if (n % i == 0)
return false;
}
return true;
}
ll modi(ll a, ll m) { return power(a, m - 2, m); }
void kmp(string s, ll p[]) {
int n = (int)s.length();
p[0] = 0;
for (int i = 1; i < n; i++) {
int j = p[i - 1];
while (j > 0 && s[i] != s[j])
j = p[j - 1];
if (s[i] == s[j])
j++;
p[i] = j;
}
}
void zfunc(string s, ll z[]) {
ll n = (ll)s.length();
z[0] = 0;
for (ll i = 1, l = 0, r = 0; i < n; ++i) {
if (i <= r)
z[i] = min(r - i + 1, z[i - l]);
while (i + z[i] < n && s[z[i]] == s[i + z[i]])
++z[i];
if (i + z[i] - 1 > r)
l = i, r = i + z[i] - 1;
}
}
struct pair_hash {
size_t operator()(const pair<int, int> &p) const noexcept {
return hash<ll>()((((ll)p.first) << 32) | ((ll)p.second));
}
};
bool palin(string s) {
ll i, n;
n = s.length();
for (i = 0; i <= n / 2; i++) {
if (s[i] != s[n - i - 1]) {
return false;
}
}
return true;
}
ll sum(ll n) {
ll i;
i = n;
ll sum = 0;
while (i > 0) {
sum += i % 10;
i = i / 10;
}
return sum;
}
ll nCr(ll n, ll r, ll p, ll fac[]) {
if (r == 0)
return 1;
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = fac[i - 1] * i % p;
return (fac[n] * modi(fac[r], p) % p * modi(fac[n - r], p) % p) % p;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
void bfs(vector<ll> &ans, ll k) {
queue<ll> q;
while (!q.empty()) {
ll temp = q.front();
}
}
void solve(ll l, ll r) {
if (l >= r) {
return;
}
if ((r - l) % 2 == 1) {
ll start = (r + l) / 2 + 1;
ll k = -1, j = 1;
while (start != l) {
printf("%lld %lld\n", start, start + k * j);
// cout <<start <<" "<< start + k * j << endl;
if (start + k * j == l) {
break;
}
start += k * j;
j++;
k *= -1;
}
} else {
ll start = (r + l) / 2;
ll k = 1, j = 1;
while (start != l) {
printf("%lld %lld\n", start, start + k * j);
// cout << start << " " << start + k * j << endl;
if (start + k * j == l) {
break;
}
start += k * j;
j++;
k *= -1;
}
}
}
void dfs(ll start, vector<ll> adj[], bool visited[], ll dp[], ll &maxi) {
visited[start] = true;
for (auto u : adj[start]) {
if (!visited[u]) {
visited[u] = true;
dp[u] = max(dp[u], dp[start] + 1);
dfs(u, adj, visited, dp, maxi);
maxi = max(maxi, dp[u]);
}
}
}
float fab(float x) {
if (x < 0) {
return -x;
}
return x;
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ll T = 1, i, j;
// cin >> T;
while (T--) {
ll n;
cin >> n;
vector<double> v(n);
ll maxtails = (n - 1) / 2;
for (i = 0; i < n; i++) {
cin >> v[i];
}
double dp[3000][3000];
for (i = 0; i <= n; i++) {
for (j = 0; j <= maxtails; j++) {
dp[i][j] = 0;
}
}
for (i = 0; i <= maxtails; i++) {
dp[0][i] = 1.0;
}
dp[1][0] = v[0];
dp[1][1] = 1 - v[0];
for (i = 1; i < n; i++) {
for (j = 0; j <= maxtails; j++) {
dp[i + 1][j] += dp[i][j] * v[i];
dp[i + 1][j + 1] += dp[i][j] * (1 - v[i]);
}
}
double ans = 0;
// for (i = 1; i <= n; i++) {
// for (j = 0; j <= maxtails; j++) {
// cout << dp[i][j] << " ";
// }
// cout << endl;
// }
for (i = 0; i <= maxtails; i++) {
ans += dp[n][i];
// cout << dp[n][i] << endl;
}
cout << fixed << setprecision(10) << ans << endl;
}
return 0;
}
| replace | 245 | 246 | 245 | 246 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll, ll>
#define vvll vector<vector<ll>>
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(), (v).end()
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define repi(i, a, b) for (ll i = a; i >= b; --i)
#define tel(a) \
{ cout << a << "\n"; }
#define tell(a, b) \
{ cout << a << " | " << b << "\n"; }
#define telll(a, b, c) \
{ cout << a << " | " << b << " | " << c << "\n"; }
#define teln(v, n) \
{ \
cout << "v- "; \
rep(i, 0, n) cout << v[i] << " "; \
cout << "\n"; \
}
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
using namespace std;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define trace(...)
#endif
#define M 110
#define N 3010
ll n;
ld dp[N][N];
ld p[N];
ld f(ll pos, ll heads) {
if (heads < 0)
return 0.00;
if (pos < 0) {
if (!heads)
return (ld)1.00;
return 0.00;
}
if (dp[pos][heads] != -1.00)
return dp[pos][heads];
ld other = (ld)1.00;
other -= p[pos];
ld ans = f(pos - 1, heads - 1) * (p[pos]) + f(pos - 1, heads) * other;
// trace(pos,heads);
return dp[pos][heads] = ans;
}
int main() {
IOS;
freopen("inp.txt", "r", stdin);
freopen("out.txt", "w", stdout);
rep(i, 0, N) rep(j, 0, N) dp[i][j] = -1.00;
cin >> n;
rep(i, 0, n) cin >> p[i];
ld ans = (ld)0.00;
rep(i, n / 2 + 1, n + 1) ans += f(n - 1, i);
cout << setprecision(50) << ans;
return 0;
} | #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll, ll>
#define vvll vector<vector<ll>>
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(), (v).end()
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define repi(i, a, b) for (ll i = a; i >= b; --i)
#define tel(a) \
{ cout << a << "\n"; }
#define tell(a, b) \
{ cout << a << " | " << b << "\n"; }
#define telll(a, b, c) \
{ cout << a << " | " << b << " | " << c << "\n"; }
#define teln(v, n) \
{ \
cout << "v- "; \
rep(i, 0, n) cout << v[i] << " "; \
cout << "\n"; \
}
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
using namespace std;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define trace(...)
#endif
#define M 110
#define N 3010
ll n;
ld dp[N][N];
ld p[N];
ld f(ll pos, ll heads) {
if (heads < 0)
return 0.00;
if (pos < 0) {
if (!heads)
return (ld)1.00;
return 0.00;
}
if (dp[pos][heads] != -1.00)
return dp[pos][heads];
ld other = (ld)1.00;
other -= p[pos];
ld ans = f(pos - 1, heads - 1) * (p[pos]) + f(pos - 1, heads) * other;
// trace(pos,heads);
return dp[pos][heads] = ans;
}
int main() {
IOS;
if (fopen("input.txt", "r"))
freopen("inp.txt", "r", stdin), freopen("out.txt", "w", stdout);
rep(i, 0, N) rep(j, 0, N) dp[i][j] = -1.00;
cin >> n;
rep(i, 0, n) cin >> p[i];
ld ans = (ld)0.00;
rep(i, n / 2 + 1, n + 1) ans += f(n - 1, i);
cout << setprecision(50) << ans;
return 0;
} | replace | 75 | 77 | 75 | 77 | -11 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 5;
int n;
double dp[N][N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
dp[0][0] = 1;
for (int i = 1; i <= n; ++i) {
double p;
cin >> p;
for (int j = 0; j <= i; ++j) {
int k = i - j;
dp[j][k] = dp[j - 1][k] * p + dp[j][k - 1] * (1 - p);
}
}
double ans = 0;
for (int i = 0; i <= n; ++i)
if (n - i < i)
ans += dp[i][n - i];
cout << fixed << setprecision(10) << ans;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 5;
int n;
double dp[N][N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
dp[0][0] = 1;
for (int i = 1; i <= n; ++i) {
double p;
cin >> p;
for (int j = 0; j <= i; ++j) {
int k = i - j;
if (j)
dp[j][k] += dp[j - 1][k] * p;
if (k)
dp[j][k] += dp[j][k - 1] * (1 - p);
}
}
double ans = 0;
for (int i = 0; i <= n; ++i)
if (n - i < i)
ans += dp[i][n - i];
cout << fixed << setprecision(10) << ans;
return 0;
}
| replace | 21 | 22 | 21 | 25 | -11 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define MOD 1000000007
double probs[3000];
double recur(int i, int n, int heads, int tails, double sa) {
if (i == n) {
if (heads > tails)
return sa;
else
return 0;
}
double a = recur(i + 1, n, heads + 1, tails, (double)sa * probs[i]);
double b = recur(i + 1, n, heads, tails + 1, (double)sa * (1 - probs[i]));
return a + b;
}
int main() {
ll n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> probs[i];
double dp[n + 1][n + 1];
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
if (i == 0 && j == 0)
dp[i][j] = 1;
if (j > i)
dp[i][j] = 0;
if (j - 1 >= 0)
dp[i][j] += dp[i][j - 1] * (probs[i + j - 1]);
if (i - 1 >= 0)
dp[i][j] += dp[i - 1][j] * (1 - probs[i + j - 1]);
}
}
double ans = 0;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
if ((i + j == n) && (j > i))
ans += dp[i][j];
}
}
cout << setprecision(10) << ans << endl;
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define MOD 1000000007
double probs[3000];
double recur(int i, int n, int heads, int tails, double sa) {
if (i == n) {
if (heads > tails)
return sa;
else
return 0;
}
double a = recur(i + 1, n, heads + 1, tails, (double)sa * probs[i]);
double b = recur(i + 1, n, heads, tails + 1, (double)sa * (1 - probs[i]));
return a + b;
}
int main() {
ll n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> probs[i];
double dp[n + 1][n + 1];
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
if (i == 0 && j == 0)
dp[i][j] = 1;
if (i + j > n)
break;
if (j > i)
dp[i][j] = 0;
if (j - 1 >= 0)
dp[i][j] += dp[i][j - 1] * (probs[i + j - 1]);
if (i - 1 >= 0)
dp[i][j] += dp[i - 1][j] * (1 - probs[i + j - 1]);
}
}
double ans = 0;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
if ((i + j == n) && (j > i))
ans += dp[i][j];
}
}
cout << setprecision(10) << ans << endl;
}
| insert | 38 | 38 | 38 | 40 | 0 | |
p03168 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long int
#define N 100000
#define f(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define po pop_back
#define pb push_back
#define lb lower_bound
#define fi first
#define se second
#define debug(x) cout << #x << " = " << x << endl
#define ub upper_bound
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define all(x) x.begin(), x.end()
#define PI 3.14159265
#define cot cout.tie(0)
using namespace std;
/**
* @author :: Sawlani
*
*/
ll n;
double p[3000];
double dp[3000][3000];
double rec(ll i, ll head) {
if (i > n && (head > (n / 2)))
return 1;
else if (i > n)
return 0;
if (dp[i][head] > -1)
return dp[i][head];
return p[i] * rec(i + 1, head + 1) + (1.0 - p[i]) * rec(i + 1, head);
}
int main() {
cin >> n;
cout << fixed << setprecision(10);
memset(dp, -1, sizeof(dp));
f(i, 1, n) cin >> p[i];
cout << rec(1, 0);
}
| #include <bits/stdc++.h>
#define ll long long int
#define N 100000
#define f(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define po pop_back
#define pb push_back
#define lb lower_bound
#define fi first
#define se second
#define debug(x) cout << #x << " = " << x << endl
#define ub upper_bound
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define all(x) x.begin(), x.end()
#define PI 3.14159265
#define cot cout.tie(0)
using namespace std;
/**
* @author :: Sawlani
*
*/
ll n;
double p[3000];
double dp[3000][3000];
double rec(ll i, ll head) {
if (i > n && (head > (n / 2)))
return 1;
else if (i > n)
return 0;
if (dp[i][head] > -1)
return dp[i][head];
return dp[i][head] =
p[i] * rec(i + 1, head + 1) + (1.0 - p[i]) * rec(i + 1, head);
}
int main() {
cin >> n;
cout << fixed << setprecision(10);
memset(dp, -1, sizeof(dp));
f(i, 1, n) cin >> p[i];
cout << rec(1, 0);
}
| replace | 33 | 34 | 33 | 35 | TLE | |
p03168 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
void func(vector<double> &p, double &sum, int n, int i, double mult) {
int sz = p.size();
if (i == sz) {
if (n >= ceil(double(sz) / 2.0)) {
sum += mult;
}
return;
}
func(p, sum, n + 1, i + 1, mult * p[i]);
func(p, sum, n, i + 1, mult * (1 - p[i]));
}
int main() {
int n;
cin >> n;
vector<double> p;
for (int i = 0; i < n; i++) {
double x;
cin >> x;
p.push_back(x);
}
double sum = 0.0;
func(p, sum, 0, 0, 1);
cout.precision(16);
cout << sum << endl;
}
| #include <bits/stdc++.h>
using namespace std;
void func(vector<double> &p, double &sum, int n, int i, double mult) {
int sz = p.size();
if (i == sz) {
if (n >= ceil(double(sz) / 2.0)) {
sum += mult;
}
return;
}
func(p, sum, n + 1, i + 1, mult * p[i]);
func(p, sum, n, i + 1, mult * (1 - p[i]));
}
int main() {
int n;
cin >> n;
vector<double> p;
for (int i = 0; i < n; i++) {
double x;
cin >> x;
p.push_back(x);
}
double sum = 0.0;
// func(p,sum,0,0,1);
double dp[n + 1][n + 1];
for (int i = 0; i < n + 1; i++) {
for (int j = 0; j < n + 1; j++) {
dp[i][j] = 0;
}
// dp[0][i]=0;
}
dp[0][0] = 1.0;
for (int i = 1; i < n + 1; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0) {
dp[i][j] = dp[i - 1][j] * (1.0 - p[i - 1]);
} else {
dp[i][j] =
dp[i - 1][j] * (1.0 - p[i - 1]) + dp[i - 1][j - 1] * p[i - 1];
}
}
}
for (int i = ceil(double(n) / 2.0); i < n + 1; i++) {
sum += dp[n][i];
}
cout.precision(16);
cout << sum << endl;
}
| replace | 23 | 24 | 23 | 45 | TLE | |
p03168 | C++ | Runtime Error | #include <cstdio>
#include <iomanip>
#include <iostream>
using namespace std;
const int N = 3e3 + 3;
int n;
double p[N];
double dp[N][2 * N];
int main() {
// freopen("input.inp", "r", stdin);
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> p[i];
dp[1][1 + N] = p[1];
dp[1][-1 + N] = 1 - p[1];
for (int i = 1; i < N; ++i)
for (int j = -n; j <= n; ++j)
if (dp[i][j + N] != 0) {
if (j + 1 <= n)
dp[i + 1][j + 1 + N] += dp[i][j + N] * p[i + 1];
if (j - 1 >= -n)
dp[i + 1][j - 1 + N] += dp[i][j + N] * (1 - p[i + 1]);
}
double ans = 0;
for (int i = 1; i <= n; ++i)
ans += dp[n][i + N];
cout << fixed << setprecision(10) << ans;
return 0;
}
| #include <cstdio>
#include <iomanip>
#include <iostream>
using namespace std;
const int N = 3e3 + 3;
int n;
double p[N];
double dp[N][2 * N];
int main() {
// freopen("input.inp", "r", stdin);
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> p[i];
dp[1][1 + N] = p[1];
dp[1][-1 + N] = 1 - p[1];
for (int i = 1; i < n; ++i)
for (int j = -n; j <= n; ++j)
if (dp[i][j + N] != 0) {
if (j + 1 <= n)
dp[i + 1][j + 1 + N] += dp[i][j + N] * p[i + 1];
if (j - 1 >= -n)
dp[i + 1][j - 1 + N] += dp[i][j + N] * (1 - p[i + 1]);
}
double ans = 0;
for (int i = 1; i <= n; ++i)
ans += dp[n][i + N];
cout << fixed << setprecision(10) << ans;
return 0;
}
| replace | 21 | 22 | 21 | 22 | -11 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using pint = pair<int, int>;
int main() {
int N;
cin >> N;
vector<double> p(N);
rep(i, N) cin >> p[i];
vector<vector<double>> dp(N + 1, vector<double>(N + 1, 0.0));
dp[0][0] = 1.0;
rep(n, N) {
rep(j, n + 1) {
dp[n + 1][j + 1] += dp[n][j] * p[n];
dp[n + 1][j] += dp[n][j] * (1 - p[n]);
}
}
double res = 0.0;
for (int i = N / 2 + 1; i++; i <= N)
res += dp[N][i];
cout << fixed << setprecision(10) << res << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using pint = pair<int, int>;
int main() {
int N;
cin >> N;
vector<double> p(N);
rep(i, N) cin >> p[i];
vector<vector<double>> dp(N + 1, vector<double>(N + 1, 0.0));
dp[0][0] = 1.0;
rep(n, N) {
rep(j, n + 1) {
dp[n + 1][j + 1] += dp[n][j] * p[n];
dp[n + 1][j] += dp[n][j] * (1 - p[n]);
}
}
double res = 0.0;
for (int i = N / 2 + 1; i <= N; i++)
res += dp[N][i];
cout << fixed << setprecision(10) << res << endl;
} | replace | 24 | 25 | 24 | 25 | -11 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 2e3 + 7;
double a[MAX], dp[MAX][MAX];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i];
dp[0][0] = 1.;
for (int i = 1; i <= n; ++i)
for (int j = 0; j <= i; ++j)
if (j > 0)
dp[i][j] = dp[i - 1][j] * (1. - a[i]) + dp[i - 1][j - 1] * a[i];
else
dp[i][j] = dp[i - 1][j] * (1. - a[i]);
double ans = 0.;
for (int i = n / 2 + 1; i <= n; ++i)
ans += dp[n][i];
cout << fixed << setprecision(11) << ans << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 3e3 + 7;
double a[MAX], dp[MAX][MAX];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i];
dp[0][0] = 1.;
for (int i = 1; i <= n; ++i)
for (int j = 0; j <= i; ++j)
if (j > 0)
dp[i][j] = dp[i - 1][j] * (1. - a[i]) + dp[i - 1][j - 1] * a[i];
else
dp[i][j] = dp[i - 1][j] * (1. - a[i]);
double ans = 0.;
for (int i = n / 2 + 1; i <= n; ++i)
ans += dp[n][i];
cout << fixed << setprecision(11) << ans << '\n';
return 0;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p03168 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v) \
cerr << #v ":[ "; \
for (auto macro_vi : v) { \
cerr << macro_vi << " "; \
} \
cerr << "]" << endl;
#define ddump(v) \
cerr << #v ":" << endl; \
for (auto macro_row : v) { \
cerr << "["; \
for (auto macro__vi : macro_row) { \
cerr << macro__vi << " "; \
} \
cerr << "]" << endl; \
}
using lint = long long;
const int INF = 1e9;
const lint LINF = 1e18;
const lint MOD = 1e9 + 7;
const double EPS = 1e-10;
int main() {
int N;
cin >> N;
vector<long double> p(N);
rep(i, N) cin >> p[i];
// 状態 (i,j) : i 枚コインを投げて,j 枚 表面がでた状態
// per(i,j) : 状態(i,j) となる確率
vector<vector<long double>> per(N + 1, vector<long double>(N + 1, 0));
ddump(per);
per[0][0] = 1;
for (int i = 1; i <= N; i++) {
for (int j = 0; j <= N; j++) {
if (0 <= j - 1)
per[i][j] += per[i - 1][j - 1] * p[i - 1];
per[i][j] += per[i - 1][j] * (1 - p[i - 1]);
}
}
// ddump(per);
long double ans = 0;
for (int i = 0; i <= N; i++) {
if (i > N / 2)
ans += per[N][i];
}
cout << setprecision(10) << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v) \
cerr << #v ":[ "; \
for (auto macro_vi : v) { \
cerr << macro_vi << " "; \
} \
cerr << "]" << endl;
#define ddump(v) \
cerr << #v ":" << endl; \
for (auto macro_row : v) { \
cerr << "["; \
for (auto macro__vi : macro_row) { \
cerr << macro__vi << " "; \
} \
cerr << "]" << endl; \
}
using lint = long long;
const int INF = 1e9;
const lint LINF = 1e18;
const lint MOD = 1e9 + 7;
const double EPS = 1e-10;
int main() {
int N;
cin >> N;
vector<long double> p(N);
rep(i, N) cin >> p[i];
// 状態 (i,j) : i 枚コインを投げて,j 枚 表面がでた状態
// per(i,j) : 状態(i,j) となる確率
vector<vector<long double>> per(N + 1, vector<long double>(N + 1, 0));
// ddump(per);
per[0][0] = 1;
for (int i = 1; i <= N; i++) {
for (int j = 0; j <= N; j++) {
if (0 <= j - 1)
per[i][j] += per[i - 1][j - 1] * p[i - 1];
per[i][j] += per[i - 1][j] * (1 - p[i - 1]);
}
}
// ddump(per);
long double ans = 0;
for (int i = 0; i <= N; i++) {
if (i > N / 2)
ans += per[N][i];
}
cout << setprecision(10) << ans << endl;
return 0;
} | replace | 38 | 39 | 38 | 39 | TLE | |
p03168 | C++ | Runtime Error | #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define pb push_back
#define pii pair<int, int>
#define fi first
#define se second
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define dbg(x) \
{ cerr << "> " << #x << ": " << x << endl; }
#define dbg2(x, y) \
{ cerr << "> " << #x << ": " << x << " , " << #y << ": " << y << endl; }
#define dbg3(x, y, z) \
{ \
cerr << "> " << #x << ": " << x << " , " << #y << ": " << y << " , " << #z \
<< ": " << z << endl; \
}
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int inf = INT_MAX;
const double eps = 0.0000001;
const double PI = acos(-1.0);
const int MOD = 1e9 + 7;
const int N = 1e3 + 5;
double a[N], dp[N][N];
signed main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
IOS;
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
dp[1][1] = a[1];
dp[1][0] = 1 - a[1];
for (int i = 2; i <= n; i++) {
dp[i][0] = dp[i - 1][0] * (1 - a[i]);
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == 1 && j == 1)
continue;
if (j > i) {
dp[i][j] = 0;
continue;
}
dp[i][j] = dp[i - 1][j] * (1 - a[i]) + dp[i - 1][j - 1] * a[i];
}
}
double ans = 0;
for (int i = (n + 1) / 2; i <= n; i++)
ans += dp[n][i];
cout << fixed << setprecision(10) << ans << endl;
return 0;
} | #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define pb push_back
#define pii pair<int, int>
#define fi first
#define se second
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define dbg(x) \
{ cerr << "> " << #x << ": " << x << endl; }
#define dbg2(x, y) \
{ cerr << "> " << #x << ": " << x << " , " << #y << ": " << y << endl; }
#define dbg3(x, y, z) \
{ \
cerr << "> " << #x << ": " << x << " , " << #y << ": " << y << " , " << #z \
<< ": " << z << endl; \
}
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int inf = INT_MAX;
const double eps = 0.0000001;
const double PI = acos(-1.0);
const int MOD = 1e9 + 7;
const int N = 3e3 + 5;
double a[N], dp[N][N];
signed main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
IOS;
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
dp[1][1] = a[1];
dp[1][0] = 1 - a[1];
for (int i = 2; i <= n; i++) {
dp[i][0] = dp[i - 1][0] * (1 - a[i]);
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == 1 && j == 1)
continue;
if (j > i) {
dp[i][j] = 0;
continue;
}
dp[i][j] = dp[i - 1][j] * (1 - a[i]) + dp[i - 1][j - 1] * a[i];
}
}
double ans = 0;
for (int i = (n + 1) / 2; i <= n; i++)
ans += dp[n][i];
cout << fixed << setprecision(10) << ans << endl;
return 0;
}
| replace | 30 | 31 | 30 | 31 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int n;
bool visited[3000][3000];
double dp[3000][3000];
double solve(int h, int t, double *p) {
if (visited[h][t] == true)
return dp[h][t];
else {
if (h > t) {
dp[h][t] = 0;
visited[h][t] = true;
return 0;
}
else if (h == t && t == 1) {
dp[h][t] = p[t - 1];
visited[h][t] = true;
return dp[h][t];
}
else if (h == 0 && t == 1) {
dp[h][t] = 1 - p[t - 1];
visited[h][t] = true;
return dp[h][t];
}
else {
dp[h][t] = p[t - 1] * solve(h - 1, t - 1, p) +
(1 - p[t - 1]) * solve(h, t - 1, p);
visited[h][t] = true;
return dp[h][t];
}
}
}
int main() {
cin >> n;
double p[n];
for (int i = 0; i < n; i++)
cin >> p[i];
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++)
visited[i][j] = false;
double pro = 0;
for (int i = n / 2 + 1; i <= n; i++) {
pro += solve(i, n, p);
}
cout.precision(9);
cout << fixed << pro << endl;
}
| #include <bits/stdc++.h>
#define ll long long
using namespace std;
int n;
bool visited[3000][3000];
double dp[3000][3000];
double solve(int h, int t, double *p) {
if (visited[h][t] == true)
return dp[h][t];
else {
if (h > t) {
dp[h][t] = 0;
visited[h][t] = true;
return 0;
}
else if (h == t && t == 1) {
dp[h][t] = p[t - 1];
visited[h][t] = true;
return dp[h][t];
}
else if (h == 0 && t == 1) {
dp[h][t] = 1 - p[t - 1];
visited[h][t] = true;
return dp[h][t];
}
else {
dp[h][t] = ((h == 0) ? 0 : (p[t - 1] * solve(h - 1, t - 1, p))) +
(1 - p[t - 1]) * solve(h, t - 1, p);
visited[h][t] = true;
return dp[h][t];
}
}
}
int main() {
cin >> n;
double p[n];
for (int i = 0; i < n; i++)
cin >> p[i];
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++)
visited[i][j] = false;
double pro = 0;
for (int i = n / 2 + 1; i <= n; i++) {
pro += solve(i, n, p);
}
cout.precision(9);
cout << fixed << pro << endl;
}
| replace | 36 | 37 | 36 | 37 | 0 | |
p03168 | C++ | Time Limit Exceeded | /************
* @Just Another Source code by: ankit.sangwan1999
* @created on: 25 May 2020
*/
#include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL) //;cout.tie(NULL)
#define ll long long
const int mod = 1e9 + 7;
#define endl '\n'
int n;
int t_max;
vector<double> prr;
double dp[3000][3000];
bool vis[3000][3000];
double fun(int ind, int curr_tails) {
// if(vis[ind][curr_tails]) {
// return dp[ind][curr_tails];
// }
// vis[ind][curr_tails] = 1;
double pos1 = 0, pos2 = 0;
if (curr_tails < t_max) {
pos1 = (1 - prr[ind]);
if (ind - 1 >= 0) {
if (vis[ind - 1][curr_tails + 1] == 0) {
dp[ind - 1][curr_tails + 1] = fun(ind - 1, curr_tails + 1);
}
pos1 *= dp[ind - 1][curr_tails + 1];
}
}
pos2 = prr[ind];
if (ind - 1 >= 0) {
if (vis[ind - 1][curr_tails] == 0) {
dp[ind - 1][curr_tails] = fun(ind - 1, curr_tails);
}
pos2 *= dp[ind - 1][curr_tails];
}
return dp[ind][curr_tails] = pos1 + pos2;
}
signed main() {
fastio;
cin >> n;
for (int i = 0; i < 3000; i++)
for (int j = 0; j < 3000; j++)
vis[i][j] = 0;
if (n & 1)
t_max = n / 2;
else
t_max = n / 2 - 1;
prr = vector<double>(n);
for (int i = 0; i < n; i++)
cin >> setprecision(10) >> prr[i];
cout << setprecision(10) << fun(n - 1, 0);
return 0;
} | /************
* @Just Another Source code by: ankit.sangwan1999
* @created on: 25 May 2020
*/
#include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL) //;cout.tie(NULL)
#define ll long long
const int mod = 1e9 + 7;
#define endl '\n'
int n;
int t_max;
vector<double> prr;
double dp[3000][3000];
bool vis[3000][3000];
double fun(int ind, int curr_tails) {
if (vis[ind][curr_tails]) {
return dp[ind][curr_tails];
}
vis[ind][curr_tails] = 1;
double pos1 = 0, pos2 = 0;
if (curr_tails < t_max) {
pos1 = (1 - prr[ind]);
if (ind - 1 >= 0) {
if (vis[ind - 1][curr_tails + 1] == 0) {
dp[ind - 1][curr_tails + 1] = fun(ind - 1, curr_tails + 1);
}
pos1 *= dp[ind - 1][curr_tails + 1];
}
}
pos2 = prr[ind];
if (ind - 1 >= 0) {
if (vis[ind - 1][curr_tails] == 0) {
dp[ind - 1][curr_tails] = fun(ind - 1, curr_tails);
}
pos2 *= dp[ind - 1][curr_tails];
}
return dp[ind][curr_tails] = pos1 + pos2;
}
signed main() {
fastio;
cin >> n;
for (int i = 0; i < 3000; i++)
for (int j = 0; j < 3000; j++)
vis[i][j] = 0;
if (n & 1)
t_max = n / 2;
else
t_max = n / 2 - 1;
prr = vector<double>(n);
for (int i = 0; i < n; i++)
cin >> setprecision(10) >> prr[i];
cout << setprecision(10) << fun(n - 1, 0);
return 0;
} | replace | 21 | 25 | 21 | 25 | TLE | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef array<ll, 2> pll;
const ll NMAX = 1005, MOD = 1e9 + 7;
ld dp[NMAX][NMAX];
int main() {
ll n;
ld p, ans = 0;
cin >> n;
dp[0][0] = 1;
for (ll i = 1; i <= n; i++) {
cin >> p;
for (ll cnt = 0; cnt <= i; cnt++) {
dp[i][cnt] = dp[i - 1][cnt - 1] * p + dp[i - 1][cnt] * (1 - p);
}
}
for (ll i = n / 2 + 1; i <= n; i++)
ans += dp[n][i];
cout << fixed << setprecision(9) << ans;
return 0;
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef array<ll, 2> pll;
const ll NMAX = 3005, MOD = 1e9 + 7;
ld dp[NMAX][NMAX];
int main() {
ll n;
ld p, ans = 0;
cin >> n;
dp[0][0] = 1;
for (ll i = 1; i <= n; i++) {
cin >> p;
for (ll cnt = 0; cnt <= i; cnt++) {
dp[i][cnt] = dp[i - 1][cnt - 1] * p + dp[i - 1][cnt] * (1 - p);
}
}
for (ll i = n / 2 + 1; i <= n; i++)
ans += dp[n][i];
cout << fixed << setprecision(9) << ans;
return 0;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
#define FAST_IO \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
const int MOD = 1e9 + 7;
void add_self(int &a, int b) {
a += b;
if (a >= MOD) {
a -= MOD;
}
}
void sub_self(int &a, int b) {
a -= b;
if (a < 0) {
a += MOD;
}
}
const int MAXN = 1e3 + 5;
int main() {
#ifndef ONLINE_JUDGE
(void)freopen("input.txt", "r", stdin);
(void)freopen("output.txt", "w", stdout);
#endif
FAST_IO;
// dp[k] // the prob that there are k heads so far
// if we toss i times, k times heads -> i-k times tail s
int n;
cin >> n;
double p;
vector<double> dp(n + 1);
dp[0] = 1;
for (int coin = 0; coin < n; ++coin) {
cin >> p;
for (int i = coin + 1; i >= 0; --i) {
dp[i] = (i == 0 ? 0 : dp[i - 1] * p) + dp[i] * (1 - p);
}
}
double answer = 0.0;
for (int heads = 0; heads <= n; ++heads) {
int tails = n - heads;
if (heads > tails)
answer += dp[heads];
}
printf("%.10lf", answer);
return 0;
}
| #include <bits/stdc++.h>
#define FAST_IO \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
const int MOD = 1e9 + 7;
void add_self(int &a, int b) {
a += b;
if (a >= MOD) {
a -= MOD;
}
}
void sub_self(int &a, int b) {
a -= b;
if (a < 0) {
a += MOD;
}
}
const int MAXN = 1e3 + 5;
int main() {
FAST_IO;
// dp[k] // the prob that there are k heads so far
// if we toss i times, k times heads -> i-k times tail s
int n;
cin >> n;
double p;
vector<double> dp(n + 1);
dp[0] = 1;
for (int coin = 0; coin < n; ++coin) {
cin >> p;
for (int i = coin + 1; i >= 0; --i) {
dp[i] = (i == 0 ? 0 : dp[i - 1] * p) + dp[i] * (1 - p);
}
}
double answer = 0.0;
for (int heads = 0; heads <= n; ++heads) {
int tails = n - heads;
if (heads > tails)
answer += dp[heads];
}
printf("%.10lf", answer);
return 0;
}
| replace | 31 | 35 | 31 | 32 | TLE | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define PB emplace_back
using namespace std;
const int N = 1e3 + 100, mod = 1e9 + 7;
long double dp[N];
int main() {
cout << setprecision(12) << fixed;
dp[0] = 1;
long long int n;
cin >> n;
for (int i = 0; i < n; i++) {
long double x;
cin >> x;
for (int j = i + 1; j >= 0; j--) {
dp[j] = dp[j] * (1 - x);
if (j != 0)
dp[j] += dp[j - 1] * x;
}
}
long long int sag = (n + 1) / 2;
long double ans = 0;
for (int i = sag; i <= n; i++)
ans += dp[i];
cout << ans;
}
| #include <bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define PB emplace_back
using namespace std;
const int N = 1e4 + 100, mod = 1e9 + 7;
long double dp[N];
int main() {
cout << setprecision(12) << fixed;
dp[0] = 1;
long long int n;
cin >> n;
for (int i = 0; i < n; i++) {
long double x;
cin >> x;
for (int j = i + 1; j >= 0; j--) {
dp[j] = dp[j] * (1 - x);
if (j != 0)
dp[j] += dp[j - 1] * x;
}
}
long long int sag = (n + 1) / 2;
long double ans = 0;
for (int i = sag; i <= n; i++)
ans += dp[i];
cout << ans;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p03168 | C++ | Runtime Error | #include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
std::cout << fixed << setprecision(10);
int n;
cin >> n;
vector<double> dp((n + 1) / 2, 0);
dp[0] = 1.0;
for (int i = 0; i < n; i++) {
double p;
cin >> p;
p = 1 - p;
for (int j = min(i + 1, (n + 1) / 2); j > 0; j--) {
dp[j] = dp[j] * (1 - p) + dp[j - 1] * p;
}
dp[0] = dp[0] * (1 - p);
}
cout << accumulate(dp.begin(), dp.end(), 0.0);
return 0;
}
| #include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
std::cout << fixed << setprecision(10);
int n;
cin >> n;
vector<double> dp((n + 1) / 2, 0);
dp[0] = 1.0;
for (int i = 0; i < n; i++) {
double p;
cin >> p;
p = 1 - p;
for (int j = min(i + 1, n / 2); j > 0; j--) {
dp[j] = dp[j] * (1 - p) + dp[j - 1] * p;
}
dp[0] = dp[0] * (1 - p);
}
cout << accumulate(dp.begin(), dp.end(), 0.0);
return 0;
}
| replace | 23 | 24 | 23 | 24 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-ffloat-store")
#pragma GCC optimize("-fno-defer-pop")
#define all(a) a.begin(), a.end()
#define ll long long int
#define ps push_back
#define fs first
#define sc second
#define mkp make_pair
#define mod 1000000007
double dp[3000][3000];
double maxval(double ar[], ll i, ll n, ll h, ll t) {
// ll t=i-h;
if (i == n) {
if (h > t)
return 1.0;
else
return 0.0;
}
// cout<<i<<" "<<h<<" "<<dp[i][h]<<endl;
if (dp[i][h] != 100.0) {
return dp[i][h];
}
double a = 0.0, b = 0.0;
a = ar[i] * maxval(ar, i + 1, n, h + 1, t);
b = (1.0 - ar[i]) * maxval(ar, i + 1, n, h, t + 1);
dp[i][h] = (a + b);
return dp[i][h];
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll i, j, k, l, n;
cin >> n;
for (i = 0; i < 3000; i++) {
for (j = 0; j < 3000; j++) {
dp[i][j] = 100.0;
}
}
double ar[n];
for (i = 0; i < n; i++) {
cin >> ar[i];
}
double an = maxval(ar, 0, n, 0, 0);
cout << setprecision(10) << an;
return 0;
}
// ctrl H replace | #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-ffloat-store")
#pragma GCC optimize("-fno-defer-pop")
#define all(a) a.begin(), a.end()
#define ll long long int
#define ps push_back
#define fs first
#define sc second
#define mkp make_pair
#define mod 1000000007
double dp[3000][3000];
double maxval(double ar[], ll i, ll n, ll h, ll t) {
// ll t=i-h;
if (i == n) {
if (h > t)
return 1.0;
else
return 0.0;
}
// cout<<i<<" "<<h<<" "<<dp[i][h]<<endl;
if (dp[i][h] != 100.0) {
return dp[i][h];
}
double a = 0.0, b = 0.0;
a = ar[i] * maxval(ar, i + 1, n, h + 1, t);
b = (1.0 - ar[i]) * maxval(ar, i + 1, n, h, t + 1);
dp[i][h] = (a + b);
return dp[i][h];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll i, j, k, l, n;
cin >> n;
for (i = 0; i < 3000; i++) {
for (j = 0; j < 3000; j++) {
dp[i][j] = 100.0;
}
}
double ar[n];
for (i = 0; i < n; i++) {
cin >> ar[i];
}
double an = maxval(ar, 0, n, 0, 0);
cout << setprecision(10) << an;
return 0;
}
// ctrl H replace | replace | 36 | 40 | 36 | 37 | -11 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define sz(a) int(a.size())
#define ll long long
#define ull unsigned long long
// #define mod int(1e9+7)
#define endl '\n'
#define Engz \
ios::sync_with_stdio(0); \
ios_base::sync_with_stdio(0); \
cin.tie(0), cout.tie(0);
#define pi double(acos(-1))
#define S second
#define F first
// freopen("input.txt","r",stdin);
//------------------- BESH ----------------------//
long long mod;
long long p(long long a, long long b) {
if (b == 0)
return 1;
long long z = p(a, b / 2);
if (b % 2 == 0)
return ((z % mod) * (z % mod)) % mod;
else
return (((z * z) % mod) * a) % mod;
}
long long g(long long a, long long b) {
if (a == 0)
return b;
else
return g(b % a, a);
}
//-----------sieve --------------------//
bool prime[1000001];
void sieve() {
memset(prime, true, sizeof prime);
prime[0] = prime[1] = 0;
for (int i = 2; i * i <= 1000000; i++) {
if (prime[i] == true)
for (int j = i * i; j <= 100000; j += i)
prime[j] = false;
}
}
ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); }
long double a[3005];
long double ans[1003][1003];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
ans[1][0] = 1.0 - a[1];
ans[1][1] = a[1];
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= n; j++) {
if (j <= i) {
ans[i][j] = ans[i - 1][j] * (1 - a[i]);
if (j)
ans[i][j] += ans[i - 1][j - 1] * a[i];
}
else
ans[i][j] = 0;
}
}
long double res = 0;
for (int i = ceil((long double)n / 2); i <= n; i++)
res += ans[n][i];
cout << setprecision(12) << fixed << res;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define sz(a) int(a.size())
#define ll long long
#define ull unsigned long long
// #define mod int(1e9+7)
#define endl '\n'
#define Engz \
ios::sync_with_stdio(0); \
ios_base::sync_with_stdio(0); \
cin.tie(0), cout.tie(0);
#define pi double(acos(-1))
#define S second
#define F first
// freopen("input.txt","r",stdin);
//------------------- BESH ----------------------//
long long mod;
long long p(long long a, long long b) {
if (b == 0)
return 1;
long long z = p(a, b / 2);
if (b % 2 == 0)
return ((z % mod) * (z % mod)) % mod;
else
return (((z * z) % mod) * a) % mod;
}
long long g(long long a, long long b) {
if (a == 0)
return b;
else
return g(b % a, a);
}
//-----------sieve --------------------//
bool prime[1000001];
void sieve() {
memset(prime, true, sizeof prime);
prime[0] = prime[1] = 0;
for (int i = 2; i * i <= 1000000; i++) {
if (prime[i] == true)
for (int j = i * i; j <= 100000; j += i)
prime[j] = false;
}
}
ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); }
long double a[3005];
long double ans[3005][3005];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
ans[1][0] = 1.0 - a[1];
ans[1][1] = a[1];
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= n; j++) {
if (j <= i) {
ans[i][j] = ans[i - 1][j] * (1 - a[i]);
if (j)
ans[i][j] += ans[i - 1][j - 1] * a[i];
}
else
ans[i][j] = 0;
}
}
long double res = 0;
for (int i = ceil((long double)n / 2); i <= n; i++)
res += ans[n][i];
cout << setprecision(12) << fixed << res;
return 0;
}
| replace | 57 | 58 | 57 | 58 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define frab(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7;
const ll INF = 2e15 + 10;
const ll MAX = 1e14 + 10;
const ld EPS = 1e-9;
const int N = 1e3 + 10;
const int M = 1e5 + 10;
ld p[N];
void solve() {
int n;
cin >> n;
fr(i, n) cin >> p[i];
vector<ld> cnt(n + 1, 0);
cnt[0] = 1;
fr(i, n) {
vector<ld> ncnt(n + 1, 0);
fr(j, n) {
ncnt[j + 1] += cnt[j] * p[i];
ncnt[j] += cnt[j] * (1 - p[i]);
}
cnt = ncnt;
}
ld ans = accumulate(cnt.begin() + (n + 1) / 2, cnt.end(), 0.0);
cout << fixed << setprecision(12) << ans;
}
int main() {
// freopen("a.in", "r", stdin);
ios_base::sync_with_stdio(false);
solve();
}
| #include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define frab(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7;
const ll INF = 2e15 + 10;
const ll MAX = 1e14 + 10;
const ld EPS = 1e-9;
const int N = 3e3 + 10;
const int M = 1e5 + 10;
ld p[N];
void solve() {
int n;
cin >> n;
fr(i, n) cin >> p[i];
vector<ld> cnt(n + 1, 0);
cnt[0] = 1;
fr(i, n) {
vector<ld> ncnt(n + 1, 0);
fr(j, n) {
ncnt[j + 1] += cnt[j] * p[i];
ncnt[j] += cnt[j] * (1 - p[i]);
}
cnt = ncnt;
}
ld ans = accumulate(cnt.begin() + (n + 1) / 2, cnt.end(), 0.0);
cout << fixed << setprecision(12) << ans;
}
int main() {
// freopen("a.in", "r", stdin);
ios_base::sync_with_stdio(false);
solve();
}
| replace | 14 | 15 | 14 | 15 | 0 | |
p03168 | C++ | Runtime Error | #pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int N;
vector<double> v;
double memo[1009][1009];
bool vis[1009][1009];
bool g[1009][1009];
ll mod = 1e9 + 7;
double sol(int pos, int k) {
if (pos == N)
return k > (N / 2);
if (vis[pos][k])
return memo[pos][k];
vis[pos][k] = 1;
return memo[pos][k] =
sol(pos + 1, k + 1) * v[pos] + sol(pos + 1, k) * (1 - v[pos]);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
cin >> N;
for (int i = 0; i < N; i++) {
double a;
cin >> a;
v.push_back(a);
}
cout << fixed << setprecision(20) << sol(0, 0);
return 0;
} | #pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int N;
vector<double> v;
double memo[3009][3009];
bool vis[3009][3009];
ll mod = 1e9 + 7;
double sol(int pos, int k) {
if (pos == N)
return k > (N / 2);
if (vis[pos][k])
return memo[pos][k];
vis[pos][k] = 1;
return memo[pos][k] =
sol(pos + 1, k + 1) * v[pos] + sol(pos + 1, k) * (1 - v[pos]);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
cin >> N;
for (int i = 0; i < N; i++) {
double a;
cin >> a;
v.push_back(a);
}
cout << fixed << setprecision(20) << sol(0, 0);
return 0;
} | replace | 7 | 10 | 7 | 9 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define fi first
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define fit(x) for (auto it = x.begin(); it != x.end(); ++it)
#define se second
#define mp make_pair
#define ALL(x) x.begin(), x.end()
#define ALP "abcdefghijklmnopqrstuvwxyz"
#define nline cout << "\n"
#define rep(i, x) for (i = 0; i < x; ++i)
#define repr(i, a, b) for (i = a; i <= b; ++i)
#define PLL pair<ll, ll>
#define VLL vector<ll>
#define W(t) while (t--)
#define modsum(a, b, M) (a % M + b % M) % M
#define modsub(a, b, M) (a % M - b % M + M) % M
#define modmul(a, b, M) (a % M * b % M) % M
#define moddiv(a, b, M) (a % M * modinv(b, M) % M) % M
#define seperate cout << "*****************\n";
const long long mi2 = 500000004;
const long long mi3 = 333333336;
const long long MOD = 1000000007;
#define ordered_set \
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define ordered_pset \
tree<PLL, null_type, less<PLL>, rb_tree_tag, \
tree_order_statistics_node_update>
int xcod[4] = {-1, 0, 1, 0};
int ycod[4] = {0, 1, 0, -1};
#define dbg(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
struct HASH {
size_t operator()(const pair<ll, ll> &x) const {
return hash<long long>()(((long long)x.first) ^
(((long long)x.second) << 32));
}
};
// unordered_map<pair<int,int>,int,HASH>mp;
// unordered_map<ll, ll, custom_hash> safe_map;
ll powermod(ll x, ll n, ll M) {
ll result = 1;
while (n > 0) {
if (n % 2 == 1)
result = (result * x) % M;
x = (x * x) % M;
n = n / 2;
}
return result;
}
vector<ll> readll() {
cin >> ws;
vector<ll> v;
string input;
getline(cin, input);
cout << input;
istringstream is(input);
ll num;
while (is >> num)
v.pb(num);
return v;
}
/*
int BLOCK_SIZE;
inline bool mo_cmp(const pair< pair<int, int>, int> &x,const pair< pair<int,
int>, int> &y)
{
if ( (x.fi.fi/BLOCK_SIZE) != (y.fi.fi/BLOCK_SIZE) )
return x < y ;
return ((x.fi.fi/BLOCK_SIZE)&1)^(x.fi.se<y.fi.se) ;
}
*/
ll modinv(ll n, ll p) { return powermod(n, p - 2, p); }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll fact[1000005], invf[1000005];
void facmod(ll n, ll M) {
ll i;
fact[0] = fact[1] = 1;
for (i = 2; i <= n; ++i) {
fact[i] = ((fact[i - 1]) % M * (i % M)) % M;
}
invf[n] = modinv(fact[n], M);
for (i = n - 1; i >= 0; --i) {
invf[i] = invf[i + 1] * (i + 1);
invf[i] %= M;
}
}
/*
ll T=0;
ll p[200005], d[200005];
ll tin[200005], tout[200005];
vector<ll> g[200005];
bool vis[200005];
void dfs(ll v,ll par=1,ll dep=0) {
//dbg(v);
tin[v] = T++;
vis[v]=true;
p[v] = par;
d[v] = dep;
for (auto to : g[v]) {
if (vis[to]) continue;
dfs(to,v,dep+1);
}
tout[v] = T++;
}
*/
// ll treeSet() {
// ordered_set o_set;
// o_set.insert(1); //for duplicate elements use pair and use second element
// unique
// // find by order returns iterator of ith largest element;
// cout<<*(o_set.find_by_order(1)) //second smallest element;
// // Finding the number of elements
// // strictly less than k=4
// cout << o_set.order_of_key(4) ;
// // Deleting 2 from the set if it exists
// if (o_set.find(2) != o_set.end())
// o_set.erase(o_set.find(2));
// }
void solve() {
ll i, j, n;
cin >> n;
long double p[n + 4];
repr(i, 1, n) { cin >> p[i]; }
long double dp[n + 4][n + 4];
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
repr(i, 1, n) { dp[0][i] = dp[0][i - 1] * (1 - p[i]); }
repr(i, 1, n) {
repr(j, 1, n) {
dp[i][j] = dp[i][j - 1] * (1 - p[j]) + dp[i - 1][j - 1] * p[j];
}
}
long double ans = 0;
repr(i, n / 2 + 1, n) { ans += dp[i][n]; }
printf("%.10Lf", ans);
// cout<<ans;
}
int main() {
fastio;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
// freopen("output.txt","w",stdout);
#endif
ll t = 1;
// cin>>t;
W(t) { solve(); }
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define fi first
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define fit(x) for (auto it = x.begin(); it != x.end(); ++it)
#define se second
#define mp make_pair
#define ALL(x) x.begin(), x.end()
#define ALP "abcdefghijklmnopqrstuvwxyz"
#define nline cout << "\n"
#define rep(i, x) for (i = 0; i < x; ++i)
#define repr(i, a, b) for (i = a; i <= b; ++i)
#define PLL pair<ll, ll>
#define VLL vector<ll>
#define W(t) while (t--)
#define modsum(a, b, M) (a % M + b % M) % M
#define modsub(a, b, M) (a % M - b % M + M) % M
#define modmul(a, b, M) (a % M * b % M) % M
#define moddiv(a, b, M) (a % M * modinv(b, M) % M) % M
#define seperate cout << "*****************\n";
const long long mi2 = 500000004;
const long long mi3 = 333333336;
const long long MOD = 1000000007;
#define ordered_set \
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define ordered_pset \
tree<PLL, null_type, less<PLL>, rb_tree_tag, \
tree_order_statistics_node_update>
int xcod[4] = {-1, 0, 1, 0};
int ycod[4] = {0, 1, 0, -1};
#define dbg(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
struct HASH {
size_t operator()(const pair<ll, ll> &x) const {
return hash<long long>()(((long long)x.first) ^
(((long long)x.second) << 32));
}
};
// unordered_map<pair<int,int>,int,HASH>mp;
// unordered_map<ll, ll, custom_hash> safe_map;
ll powermod(ll x, ll n, ll M) {
ll result = 1;
while (n > 0) {
if (n % 2 == 1)
result = (result * x) % M;
x = (x * x) % M;
n = n / 2;
}
return result;
}
vector<ll> readll() {
cin >> ws;
vector<ll> v;
string input;
getline(cin, input);
cout << input;
istringstream is(input);
ll num;
while (is >> num)
v.pb(num);
return v;
}
/*
int BLOCK_SIZE;
inline bool mo_cmp(const pair< pair<int, int>, int> &x,const pair< pair<int,
int>, int> &y)
{
if ( (x.fi.fi/BLOCK_SIZE) != (y.fi.fi/BLOCK_SIZE) )
return x < y ;
return ((x.fi.fi/BLOCK_SIZE)&1)^(x.fi.se<y.fi.se) ;
}
*/
ll modinv(ll n, ll p) { return powermod(n, p - 2, p); }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll fact[1000005], invf[1000005];
void facmod(ll n, ll M) {
ll i;
fact[0] = fact[1] = 1;
for (i = 2; i <= n; ++i) {
fact[i] = ((fact[i - 1]) % M * (i % M)) % M;
}
invf[n] = modinv(fact[n], M);
for (i = n - 1; i >= 0; --i) {
invf[i] = invf[i + 1] * (i + 1);
invf[i] %= M;
}
}
/*
ll T=0;
ll p[200005], d[200005];
ll tin[200005], tout[200005];
vector<ll> g[200005];
bool vis[200005];
void dfs(ll v,ll par=1,ll dep=0) {
//dbg(v);
tin[v] = T++;
vis[v]=true;
p[v] = par;
d[v] = dep;
for (auto to : g[v]) {
if (vis[to]) continue;
dfs(to,v,dep+1);
}
tout[v] = T++;
}
*/
// ll treeSet() {
// ordered_set o_set;
// o_set.insert(1); //for duplicate elements use pair and use second element
// unique
// // find by order returns iterator of ith largest element;
// cout<<*(o_set.find_by_order(1)) //second smallest element;
// // Finding the number of elements
// // strictly less than k=4
// cout << o_set.order_of_key(4) ;
// // Deleting 2 from the set if it exists
// if (o_set.find(2) != o_set.end())
// o_set.erase(o_set.find(2));
// }
void solve() {
ll i, j, n;
cin >> n;
long double p[n + 4];
repr(i, 1, n) { cin >> p[i]; }
long double dp[n + 4][n + 4];
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
repr(i, 1, n) { dp[0][i] = dp[0][i - 1] * (1 - p[i]); }
repr(i, 1, n) {
repr(j, 1, n) {
dp[i][j] = dp[i][j - 1] * (1 - p[j]) + dp[i - 1][j - 1] * p[j];
}
}
long double ans = 0;
repr(i, n / 2 + 1, n) { ans += dp[i][n]; }
printf("%.10Lf", ans);
// cout<<ans;
}
int main() {
fastio;
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// //freopen("output.txt","w",stdout);
// #endif
ll t = 1;
// cin>>t;
W(t) { solve(); }
return 0;
} | replace | 174 | 178 | 174 | 178 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
double a[N], sum, d[N][N];
int n, kek;
int main() {
cin >> n;
d[0][0] = 1;
for (int i = 1; i <= n; i++) {
cin >> a[i];
d[i][0] = 1;
}
d[n][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
d[i][j] = d[i - 1][j - 1] * a[i] + d[i - 1][j] * (1 - a[i]);
}
}
if (n % 2 == 1) {
kek = int(n / 2) + 1;
} else {
kek = int(n / 2);
}
for (int i = kek; i <= n; i++) {
sum += d[n][i];
}
printf("%.10f", d[n][kek]);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 10;
double a[N], sum, d[N][N];
int n, kek;
int main() {
cin >> n;
d[0][0] = 1;
for (int i = 1; i <= n; i++) {
cin >> a[i];
d[i][0] = 1;
}
d[n][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
d[i][j] = d[i - 1][j - 1] * a[i] + d[i - 1][j] * (1 - a[i]);
}
}
if (n % 2 == 1) {
kek = int(n / 2) + 1;
} else {
kek = int(n / 2);
}
for (int i = kek; i <= n; i++) {
sum += d[n][i];
}
printf("%.10f", d[n][kek]);
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p03168 | C++ | Runtime Error | /* aman36 - Aman Raj */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define IOS \
ios ::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define AfterDecimal(n) cout << fixed << setprecision(n);
#define pb push_back
#define pp(a, b) pair<a, b>
#define ll long long
#define ld long double
#define all(a) a.begin(), a.end()
#define pi pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
#define itr iterator
#define bits(x) __builtin_popcount(x)
#define fori(n) for (ll i = 0; i < n; i++)
#define forj(n) for (ll j = 0; j < n; j++)
#define fork(n) for (ll k = 0; k < n; k++)
#define forlp(k, x, n) for (ll k = x; k <= n; k++)
#define vll vector<ll>
#define mll map<ll, ll>
#define vpll vector<pll>
#define mem(x) memset(x, 0, sizeof(x));
#define int ll
#define endl "\n"
using namespace __gnu_pbds;
using namespace std;
template <class T> T printr(T p) {
cout << p << '\n';
return 0;
}
template <class T> T printe(T p) {
cout << p << '\n';
exit(0);
}
template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cout << "# " << name << " = " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cout << "# ";
cout.write(names, comma - names) << " = " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define debug(...) 36
#endif
ll mxm() { return LLONG_MIN; }
template <typename... Args> ll mxm(ll a, Args... args) {
return max(a, mxm(args...));
}
ll mnm() { return LLONG_MAX; }
template <typename... Args> ll mnm(ll a, Args... args) {
return min(a, mnm(args...));
}
template <class T> ostream &operator<<(ostream &os, vector<T> V) {
os << "[ ";
for (auto v : V)
os << v << " ";
return os << "]";
}
template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
return os << "(" << P.first << "," << P.second << ")";
}
int power(int lx, int ly, int p) {
ll res = 1;
ll x = lx;
ll y = ly;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return (int)res;
}
bool isPrime(int n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
const ll INF = (ll)(8e18);
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const int maxn = 1e6 + 5;
// check the limits
const int N = 1005;
double dp[N][N];
int32_t main() {
IOS;
#ifndef ONLINe5E_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int n, m;
cin >> n;
double a[n];
fori(n) { cin >> a[i]; }
AfterDecimal(10);
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
if (!i && !j)
dp[i][j] = (ld)1.0;
else if (!i) {
dp[i][j] = (ld)0.0;
} else if (!j) {
dp[i][j] = dp[i - 1][j] * ((ld)1.0 - a[i - 1]);
} else {
dp[i][j] =
dp[i - 1][j - 1] * a[i - 1] + ((ld)1.0 - a[i - 1]) * dp[i - 1][j];
}
// cout << dp[i][j] << " ";
}
// cout << endl;
}
ld ans = 0.0;
for (int i = 0; i <= n; i++) {
if (i > n / 2) {
ans += dp[n][i];
}
}
cout << ans << endl;
#ifdef LOCAL
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}
/* g++ -DLOCAL -DDEBUG -std=c++17 -Wshadow -Wall -o "c" "icpc.cpp"
-fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g */
// read the question correctly
// read code carefully
// corner cases // int vs ll // cin vs scanf // clear structures // maths
// check max, min set to INT_MAX instead INF
// check constraints | /* aman36 - Aman Raj */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define IOS \
ios ::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define AfterDecimal(n) cout << fixed << setprecision(n);
#define pb push_back
#define pp(a, b) pair<a, b>
#define ll long long
#define ld long double
#define all(a) a.begin(), a.end()
#define pi pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
#define itr iterator
#define bits(x) __builtin_popcount(x)
#define fori(n) for (ll i = 0; i < n; i++)
#define forj(n) for (ll j = 0; j < n; j++)
#define fork(n) for (ll k = 0; k < n; k++)
#define forlp(k, x, n) for (ll k = x; k <= n; k++)
#define vll vector<ll>
#define mll map<ll, ll>
#define vpll vector<pll>
#define mem(x) memset(x, 0, sizeof(x));
#define int ll
#define endl "\n"
using namespace __gnu_pbds;
using namespace std;
template <class T> T printr(T p) {
cout << p << '\n';
return 0;
}
template <class T> T printe(T p) {
cout << p << '\n';
exit(0);
}
template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cout << "# " << name << " = " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cout << "# ";
cout.write(names, comma - names) << " = " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define debug(...) 36
#endif
ll mxm() { return LLONG_MIN; }
template <typename... Args> ll mxm(ll a, Args... args) {
return max(a, mxm(args...));
}
ll mnm() { return LLONG_MAX; }
template <typename... Args> ll mnm(ll a, Args... args) {
return min(a, mnm(args...));
}
template <class T> ostream &operator<<(ostream &os, vector<T> V) {
os << "[ ";
for (auto v : V)
os << v << " ";
return os << "]";
}
template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
return os << "(" << P.first << "," << P.second << ")";
}
int power(int lx, int ly, int p) {
ll res = 1;
ll x = lx;
ll y = ly;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return (int)res;
}
bool isPrime(int n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
const ll INF = (ll)(8e18);
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const int maxn = 1e6 + 5;
// check the limits
const int N = 3005;
double dp[N][N];
int32_t main() {
IOS;
#ifndef ONLINe5E_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int n, m;
cin >> n;
double a[n];
fori(n) { cin >> a[i]; }
AfterDecimal(10);
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
if (!i && !j)
dp[i][j] = (ld)1.0;
else if (!i) {
dp[i][j] = (ld)0.0;
} else if (!j) {
dp[i][j] = dp[i - 1][j] * ((ld)1.0 - a[i - 1]);
} else {
dp[i][j] =
dp[i - 1][j - 1] * a[i - 1] + ((ld)1.0 - a[i - 1]) * dp[i - 1][j];
}
// cout << dp[i][j] << " ";
}
// cout << endl;
}
ld ans = 0.0;
for (int i = 0; i <= n; i++) {
if (i > n / 2) {
ans += dp[n][i];
}
}
cout << ans << endl;
#ifdef LOCAL
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}
/* g++ -DLOCAL -DDEBUG -std=c++17 -Wshadow -Wall -o "c" "icpc.cpp"
-fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g */
// read the question correctly
// read code carefully
// corner cases // int vs ll // cin vs scanf // clear structures // maths
// check max, min set to INT_MAX instead INF
// check constraints | replace | 119 | 120 | 119 | 120 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<double> p(n);
vector<double> dp(n, 0);
dp[0] = 1;
for (int i = 0; i < n; i++) {
cin >> p[i];
for (int j = i; j >= 0; j--) {
dp[j + 1] += dp[j] * p[i];
dp[j] *= 1 - p[i];
}
}
double ans = 0;
for (int i = n; i > n / 2; i--) {
ans += dp[i];
}
cout << fixed << setprecision(15) << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<double> p(n);
vector<double> dp(n + 1, 0);
dp[0] = 1;
for (int i = 0; i < n; i++) {
cin >> p[i];
for (int j = i; j >= 0; j--) {
dp[j + 1] += dp[j] * p[i];
dp[j] *= 1 - p[i];
}
}
double ans = 0;
for (int i = n; i > n / 2; i--) {
ans += dp[i];
}
cout << fixed << setprecision(15) << ans << endl;
return 0;
} | replace | 12 | 13 | 12 | 13 | 0 | |
p03168 | C++ | Time Limit Exceeded | #include <algorithm>
#include <assert.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
const int N = 1e3 + 2;
const long long MOD = 1e9 + 7;
int n;
double dp[3000][3000], p[3000];
bool vis[3000][3000];
double calc(int i, int heads) {
if (i == n) {
return heads > n / 2;
}
double &ret = dp[i][heads];
if (vis[i][heads]) {
return ret;
}
ret = calc(i + 1, heads + 1) * p[i];
ret += calc(i + 1, heads) * (1 - p[i]);
return ret;
}
int main() {
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> p[i];
}
cout << setprecision(16) << calc(0, 0) << endl;
return 0;
} | #include <algorithm>
#include <assert.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
const int N = 1e3 + 2;
const long long MOD = 1e9 + 7;
int n;
double dp[3000][3000], p[3000];
bool vis[3000][3000];
double calc(int i, int heads) {
if (i == n) {
return heads > n / 2;
}
double &ret = dp[i][heads];
if (vis[i][heads]) {
return ret;
}
vis[i][heads] = true;
ret = calc(i + 1, heads + 1) * p[i];
ret += calc(i + 1, heads) * (1 - p[i]);
return ret;
}
int main() {
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> p[i];
}
cout << setprecision(16) << calc(0, 0) << endl;
return 0;
} | insert | 32 | 32 | 32 | 33 | TLE | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, b) for (int i = 0; i < (b); ++i)
#define endl '\n'
#define sz(x) (int)x.size()
#define mod %
#define fillchar(x, y, z) memset(x, z, y)
#define pii pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define sqr(x) ((x) * (x))
typedef long long int64;
typedef unsigned long long qword;
using namespace std;
const int maxn = 1e3 + 5;
long double f[maxn][maxn];
void Input() {
int n;
cin >> n;
f[0][0] = 1;
FOR(i, 1, n) {
long double p;
cin >> p;
f[i][0] = f[i - 1][0] * (1.0 - p);
FOR(j, 1, i)
f[i][j] = (f[i - 1][j - 1] * p + f[i - 1][j] * (1.0 - p));
}
long double res = 0;
FOR(i, 1, n)
if (i > n - i)
res += f[n][i];
cout.precision(9);
cout << fixed << res;
}
void Solve() {}
int main() {
#ifdef meomeomeooooo
freopen("input.txt", "r", stdin);
// freopen(".out","w",stdout);
#endif // meomeomeooooo
iostream::sync_with_stdio(false);
cin.tie(0);
Input();
Solve();
return 0;
}
| #include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, b) for (int i = 0; i < (b); ++i)
#define endl '\n'
#define sz(x) (int)x.size()
#define mod %
#define fillchar(x, y, z) memset(x, z, y)
#define pii pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define sqr(x) ((x) * (x))
typedef long long int64;
typedef unsigned long long qword;
using namespace std;
const int maxn = 3e3 + 5;
long double f[maxn][maxn];
void Input() {
int n;
cin >> n;
f[0][0] = 1;
FOR(i, 1, n) {
long double p;
cin >> p;
f[i][0] = f[i - 1][0] * (1.0 - p);
FOR(j, 1, i)
f[i][j] = (f[i - 1][j - 1] * p + f[i - 1][j] * (1.0 - p));
}
long double res = 0;
FOR(i, 1, n)
if (i > n - i)
res += f[n][i];
cout.precision(9);
cout << fixed << res;
}
void Solve() {}
int main() {
#ifdef meomeomeooooo
freopen("input.txt", "r", stdin);
// freopen(".out","w",stdout);
#endif // meomeomeooooo
iostream::sync_with_stdio(false);
cin.tie(0);
Input();
Solve();
return 0;
}
| replace | 16 | 17 | 16 | 17 | 0 | |
p03168 | C++ | Runtime Error | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
// #include <math.h>
// #include <algorithm>
#include <vector>
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))
using namespace std;
int main(int argc, char *argv[]) {
long n;
scanf("%ld", &n);
double gp0[1500] = {0};
double gp1[1500] = {0};
gp0[0] = 1;
long i, j;
for (i = 1; i <= n; i++) {
double p = 0;
scanf("%lf", &p);
for (j = 0; j <= i; j++) {
if (i % 2 == 1) {
gp1[j] = (j > 0 ? p * gp0[j - 1] + (1 - p) * gp0[j] : (1 - p) * gp0[j]);
} else {
gp0[j] = (j > 0 ? p * gp1[j - 1] + (1 - p) * gp1[j] : (1 - p) * gp1[j]);
}
}
}
double sum = 0;
for (i = n / 2 + 1; i <= n; i++) {
sum += gp1[i];
}
printf("%.10f\n", sum);
return 0;
}
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
// #include <math.h>
// #include <algorithm>
#include <vector>
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))
using namespace std;
int main(int argc, char *argv[]) {
long n;
scanf("%ld", &n);
double gp0[3001] = {0};
double gp1[3001] = {0};
gp0[0] = 1;
long i, j;
for (i = 1; i <= n; i++) {
double p = 0;
scanf("%lf", &p);
for (j = 0; j <= i; j++) {
if (i % 2 == 1) {
gp1[j] = (j > 0 ? p * gp0[j - 1] + (1 - p) * gp0[j] : (1 - p) * gp0[j]);
} else {
gp0[j] = (j > 0 ? p * gp1[j - 1] + (1 - p) * gp1[j] : (1 - p) * gp1[j]);
}
}
}
double sum = 0;
for (i = n / 2 + 1; i <= n; i++) {
sum += gp1[i];
}
printf("%.10f\n", sum);
return 0;
}
| replace | 16 | 18 | 16 | 18 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define fr(a, b) for (int i = a; i < b; i++)
#define mod 1000000007
#define triplet pair<int, pair<int, int>>
#define fast_io \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
using namespace std;
double dp[3000][3000];
double magic(vector<double> &bias, int i, int heads) {
if (i == -1 && heads == 0)
return 1;
if (i == -1)
return 0;
if (dp[i][heads] >= 0)
return dp[i][heads];
double p1 = bias[i] * magic(bias, i - 1, heads - 1);
double p2 = (1 - bias[i]) * magic(bias, i - 1, heads);
return dp[i][heads] = p1 + p2;
}
int main() {
ll i, j, t, n, m, p, k;
fast_io;
t = 1;
// cin>>t;
while (t--) {
cin >> n;
memset(dp, -1, sizeof dp);
double ans = 0;
vector<double> coins(n);
fr(0, n) cin >> coins[i];
int reqHeads = n / 2 + 1;
while (reqHeads <= n)
ans += magic(coins, coins.size() - 1, reqHeads++);
cout << fixed << setprecision(9) << ans;
}
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define fr(a, b) for (int i = a; i < b; i++)
#define mod 1000000007
#define triplet pair<int, pair<int, int>>
#define fast_io \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
using namespace std;
double dp[3000][3000];
double magic(vector<double> &bias, int i, int heads) {
if (heads < 0)
return 0;
if (i == -1 && heads == 0)
return 1;
if (i == -1)
return 0;
if (dp[i][heads] >= 0)
return dp[i][heads];
double p1 = bias[i] * magic(bias, i - 1, heads - 1);
double p2 = (1 - bias[i]) * magic(bias, i - 1, heads);
return dp[i][heads] = p1 + p2;
}
int main() {
ll i, j, t, n, m, p, k;
fast_io;
t = 1;
// cin>>t;
while (t--) {
cin >> n;
memset(dp, -1, sizeof dp);
double ans = 0;
vector<double> coins(n);
fr(0, n) cin >> coins[i];
int reqHeads = n / 2 + 1;
while (reqHeads <= n)
ans += magic(coins, coins.size() - 1, reqHeads++);
cout << fixed << setprecision(9) << ans;
}
return 0;
}
| insert | 12 | 12 | 12 | 15 | 0 | |
p03168 | C++ | Time Limit Exceeded | /*
author: kartik8800
*/
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr(a, b) for (ll i = a; i < b; i++)
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define prDouble(x) cout << fixed << setprecision(10) << x
#define triplet pair<ll, pair<ll, ll>>
#define fast_io \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
using namespace std;
double dp[3001][3001];
double solve(vector<double> ar, int i, int heads) {
if (heads <= 0)
return 1;
if (i == 0)
return 0;
if (dp[i][heads] > -0.9)
return dp[i][heads];
return dp[i][heads] = ar[i] * solve(ar, i - 1, heads - 1) +
(1 - ar[i]) * solve(ar, i - 1, heads);
}
int main() {
int n;
cin >> n;
memset(dp, -1, sizeof dp);
vector<double> ar(n + 1);
fr(1, n + 1) cin >> ar[i];
prDouble(solve(ar, n, (n + 1) / 2));
}
| /*
author: kartik8800
*/
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr(a, b) for (ll i = a; i < b; i++)
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define prDouble(x) cout << fixed << setprecision(10) << x
#define triplet pair<ll, pair<ll, ll>>
#define fast_io \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
using namespace std;
double dp[3001][3001];
double solve(vector<double> &ar, int i, int heads) {
if (heads <= 0)
return 1;
if (i == 0)
return 0;
if (dp[i][heads] > -0.9)
return dp[i][heads];
return dp[i][heads] = ar[i] * solve(ar, i - 1, heads - 1) +
(1 - ar[i]) * solve(ar, i - 1, heads);
}
int main() {
int n;
cin >> n;
memset(dp, -1, sizeof dp);
vector<double> ar(n + 1);
fr(1, n + 1) cin >> ar[i];
prDouble(solve(ar, n, (n + 1) / 2));
}
| replace | 17 | 18 | 17 | 18 | TLE | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
typedef unsigned long long ull;
typedef long double ld;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define PI 3.14159265
const int MOD = 1e9 + 7;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) (a).begin(), (a).end()
const int N = 3e2 + 5;
double dp[N][N];
double p[N];
int n;
double go(int pos, int head) {
if (pos == n + 1) {
return head > n / 2;
}
double &ans = dp[pos][head];
if (ans != -1)
return ans;
ans = 0;
ans += (p[pos] * go(pos + 1, head + 1)) + ((1 - p[pos]) * go(pos + 1, head));
return ans;
}
int32_t main() {
IOS;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= n; j++) {
dp[i][j] = -1.0;
}
}
cout << fixed << setprecision(12) << go(1, 0) << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
typedef unsigned long long ull;
typedef long double ld;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define PI 3.14159265
const int MOD = 1e9 + 7;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) (a).begin(), (a).end()
const int N = 3005;
double dp[N][N];
double p[N];
int n;
double go(int pos, int head) {
if (pos == n + 1) {
return head > n / 2;
}
double &ans = dp[pos][head];
if (ans != -1)
return ans;
ans = 0;
ans += (p[pos] * go(pos + 1, head + 1)) + ((1 - p[pos]) * go(pos + 1, head));
return ans;
}
int32_t main() {
IOS;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= n; j++) {
dp[i][j] = -1.0;
}
}
cout << fixed << setprecision(12) << go(1, 0) << endl;
} | replace | 19 | 20 | 19 | 20 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
int N;
double p[3333];
double dp[3333][3333]; // dp[i][j]: 表i枚、裏j枚が出る確率
signed main() {
// 入力
cin >> N;
for (int i = 0; i < N; i++) {
cin >> p[i];
}
dp[0][0] = 1;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
// おもて
dp[i + 1][j] += dp[i][j] * p[i + j];
// うら
dp[i][j + 1] += dp[i][j] * (1 - p[i + j]);
}
}
double ans = 0;
for (int i = N / 2 + 1; i <= N; i++) {
int j = N - i;
ans += dp[i][j];
}
printf("%.10f\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
int N;
double p[3333];
double dp[3333][3333]; // dp[i][j]: 表i枚、裏j枚が出る確率
signed main() {
// 入力
cin >> N;
for (int i = 0; i < N; i++) {
cin >> p[i];
}
dp[0][0] = 1;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i + j > N)
continue;
// おもて
dp[i + 1][j] += dp[i][j] * p[i + j];
// うら
dp[i][j + 1] += dp[i][j] * (1 - p[i + j]);
}
}
double ans = 0;
for (int i = N / 2 + 1; i <= N; i++) {
int j = N - i;
ans += dp[i][j];
}
printf("%.10f\n", ans);
return 0;
} | insert | 19 | 19 | 19 | 21 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define dbg3(x, y, z) \
cerr << "(" << #x << ", " << #y << ", " << #z << ") = " \
<< "(" << x << ", " << y << ", " << z << ")" << endl;
template <typename T> void print2(T Array, int height, int width) {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
// cout << " " << Array[i][j];
printf("%6f ", Array[i][j]);
}
cout << endl;
}
}
int N;
double p[3333];
double dp[3333][3333]; // dp[i][j]: 表i枚、裏j枚が出る確率
signed main() {
// 入力
cin >> N;
for (int i = 0; i < N; i++) {
cin >> p[i];
}
dp[0][0] = 1;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
// おもて
dp[i + 1][j] += dp[i][j] * p[i + j];
// うら
dp[i][j + 1] += dp[i][j] * (1 - p[i + j]);
}
}
double ans = 0;
for (int i = N / 2 + 1; i <= N; i++) {
int j = N - i;
ans += dp[i][j];
}
printf("%.10f\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define dbg3(x, y, z) \
cerr << "(" << #x << ", " << #y << ", " << #z << ") = " \
<< "(" << x << ", " << y << ", " << z << ")" << endl;
template <typename T> void print2(T Array, int height, int width) {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
// cout << " " << Array[i][j];
printf("%6f ", Array[i][j]);
}
cout << endl;
}
}
int N;
double p[3333];
double dp[3333][3333]; // dp[i][j]: 表i枚、裏j枚が出る確率
signed main() {
// 入力
cin >> N;
for (int i = 0; i < N; i++) {
cin >> p[i];
}
dp[0][0] = 1;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i + j > N)
continue;
// おもて
dp[i + 1][j] += dp[i][j] * p[i + j];
// うら
dp[i][j + 1] += dp[i][j] * (1 - p[i + j]);
}
}
double ans = 0;
for (int i = N / 2 + 1; i <= N; i++) {
int j = N - i;
ans += dp[i][j];
}
printf("%.10f\n", ans);
return 0;
} | insert | 32 | 32 | 32 | 34 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
int N;
double p[3333]; // コインの表が出る確率
double dp[3333][3333];
signed main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> p[i];
}
dp[0][0] = 1; // DPテーブルを初期化
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
// おもて
dp[i + 1][j] += dp[i][j] * p[i + j];
// うら
dp[i][j + 1] += dp[i][j] * (1 - p[i + j]);
}
}
double ans = 0;
for (int i = N / 2 + 1; i <= N; i++) {
int j = N - i;
ans += dp[i][j];
}
printf("%.10f\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
int N;
double p[3333]; // コインの表が出る確率
double dp[3333][3333];
signed main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> p[i];
}
dp[0][0] = 1; // DPテーブルを初期化
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i + j > N)
continue;
// おもて
dp[i + 1][j] += dp[i][j] * p[i + j];
// うら
dp[i][j + 1] += dp[i][j] * (1 - p[i + j]);
}
}
double ans = 0;
for (int i = N / 2 + 1; i <= N; i++) {
int j = N - i;
ans += dp[i][j];
}
printf("%.10f\n", ans);
return 0;
} | insert | 18 | 18 | 18 | 20 | 0 | |
p03168 | C++ | Runtime Error | #pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define MAXN ((int)1e3 + 5)
#define MOD ((int)1e9 + 7)
#define ll long long
#define _ << " " <<
#define TRACE(x) cout << #x << " = " << x << endl;
#define pb push_back
#define MP make_pair
#define pi pair<int, int>
#define vi vector<int>
#define vii vector<pi>
#define all(x) x.begin(), x.end()
int n, m, t, k;
double p[MAXN];
double dp[MAXN][MAXN];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; ++i)
cin >> p[i];
// for (int i = 0; i < n; ++i)
// {
// cout << 1-p[i] << endl;
// }
dp[0][0] = 1.0f - p[0];
dp[0][1] = p[0];
for (int i = 1; i < n; ++i) {
for (int j = 0; j <= i + 1; ++j) {
if (j)
dp[i][j] = dp[i - 1][j] * (1.0f - p[i]) + dp[i - 1][j - 1] * (p[i]);
else
dp[i][j] = dp[i - 1][j] * (1.0f - p[i]);
}
}
double ans = 0;
for (int i = n / 2 + 1; i <= n; ++i) {
// cout << i _ dp[n-1][i] << endl;
ans += dp[n - 1][i];
}
cout << std::setprecision(12) << ans;
// for (int i = 0; i < n; ++i)
// {
// cout << i << " : ";
// for (int j = 0; j <= i+1; ++j)
// {
// cout << dp[i][j] << " ";
// }
// cout << endl;
// }
return 0;
}
| #pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define MAXN ((int)3e3 + 5)
#define MOD ((int)1e9 + 7)
#define ll long long
#define _ << " " <<
#define TRACE(x) cout << #x << " = " << x << endl;
#define pb push_back
#define MP make_pair
#define pi pair<int, int>
#define vi vector<int>
#define vii vector<pi>
#define all(x) x.begin(), x.end()
int n, m, t, k;
double p[MAXN];
double dp[MAXN][MAXN];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; ++i)
cin >> p[i];
// for (int i = 0; i < n; ++i)
// {
// cout << 1-p[i] << endl;
// }
dp[0][0] = 1.0f - p[0];
dp[0][1] = p[0];
for (int i = 1; i < n; ++i) {
for (int j = 0; j <= i + 1; ++j) {
if (j)
dp[i][j] = dp[i - 1][j] * (1.0f - p[i]) + dp[i - 1][j - 1] * (p[i]);
else
dp[i][j] = dp[i - 1][j] * (1.0f - p[i]);
}
}
double ans = 0;
for (int i = n / 2 + 1; i <= n; ++i) {
// cout << i _ dp[n-1][i] << endl;
ans += dp[n - 1][i];
}
cout << std::setprecision(12) << ans;
// for (int i = 0; i < n; ++i)
// {
// cout << i << " : ";
// for (int j = 0; j <= i+1; ++j)
// {
// cout << dp[i][j] << " ";
// }
// cout << endl;
// }
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i, a, b) for (lli i = a; i < b; i++)
#define loop(i, a, b) for (int i = a; i < b; i++)
#define mod 1000000007
#define inf 100000000000000000
#define lld long double
#define pll pair<long long int, long long int>
#define vll vector<lli>
#define eps 0.000001
#define endl '\n'
#define mo 998244353
using namespace std;
#define MAXN 200005
typedef tree<lli, null_type, less<lli>, rb_tree_tag,
tree_order_statistics_node_update>
indexed_set;
lld dp[3001][3001];
int main() {
///////////////////////////////////////////
fastio;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
///////////////////////////////////////////
lli n;
cin >> n;
lld p[n + 1];
loopl(i, 1, n + 1) cin >> p[i];
dp[0][0] = 1;
loopl(i, 1, n + 1) {
loopl(j, 0, n + 1) {
if (j > i)
break;
dp[i][j] = dp[i - 1][j] * (1 - p[i]);
if (j >= 1)
dp[i][j] += dp[i - 1][j - 1] * p[i];
}
}
lld ans = 0;
loopl(i, n / 2 + 1, n + 1) ans += dp[n][i];
cout << fixed << setprecision(12) << ans << endl;
} | #include <bits/stdc++.h>
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i, a, b) for (lli i = a; i < b; i++)
#define loop(i, a, b) for (int i = a; i < b; i++)
#define mod 1000000007
#define inf 100000000000000000
#define lld long double
#define pll pair<long long int, long long int>
#define vll vector<lli>
#define eps 0.000001
#define endl '\n'
#define mo 998244353
using namespace std;
#define MAXN 200005
typedef tree<lli, null_type, less<lli>, rb_tree_tag,
tree_order_statistics_node_update>
indexed_set;
lld dp[3001][3001];
int main() {
lli n;
cin >> n;
lld p[n + 1];
loopl(i, 1, n + 1) cin >> p[i];
dp[0][0] = 1;
loopl(i, 1, n + 1) {
loopl(j, 0, n + 1) {
if (j > i)
break;
dp[i][j] = dp[i - 1][j] * (1 - p[i]);
if (j >= 1)
dp[i][j] += dp[i - 1][j - 1] * p[i];
}
}
lld ans = 0;
loopl(i, n / 2 + 1, n + 1) ans += dp[n][i];
cout << fixed << setprecision(12) << ans << endl;
} | delete | 39 | 46 | 39 | 39 | -11 | |
p03168 | C++ | Runtime Error | #include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define ff first
#define ss second
#define END "\n"
#define pb push_back
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = 1 << 29;
typedef long long ll;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<ii> vii;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int &n, int b) { n |= two(b); }
inline void unset_bit(int &n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) {
int res = 0;
while (n && ++res)
n -= n & (-n);
return res;
}
template <class T> void chmax(T &a, const T &b) { a = max(a, b); }
template <class T> void chmin(T &a, const T &b) { a = min(a, b); }
/////////////////////////////////////////////////////////////////////
int main() {
fast int n, i, j;
long double p[3000], ans = 0;
long double dp[300][300] = {0};
cin >> n;
dp[0][0] = 1;
dp[0][1] = 0;
for (i = 1; i <= n; i++) {
cin >> p[i];
dp[i][0] = dp[i - 1][0] * (1 - p[i]);
}
// for (i = 0; i < n; i++)
// cout << p[i] << " ";
for (i = 0; i <= n; i++) {
for (j = 1; j <= i; j++) {
dp[i][j] = p[i] * dp[i - 1][j - 1] + (1 - p[i]) * dp[i - 1][j];
}
}
// for (i = 0; i <= n; i++)
// {
// for (j = 0; j <= n; j++)
// {
// cout << dp[i][j] << " ";
// }
// cout << END;
// }
for (i = 0; i <= n; i++) {
if (i > (n / 2)) {
ans += dp[n][i];
}
}
cout << setprecision(10);
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define ff first
#define ss second
#define END "\n"
#define pb push_back
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = 1 << 29;
typedef long long ll;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<ii> vii;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int &n, int b) { n |= two(b); }
inline void unset_bit(int &n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) {
int res = 0;
while (n && ++res)
n -= n & (-n);
return res;
}
template <class T> void chmax(T &a, const T &b) { a = max(a, b); }
template <class T> void chmin(T &a, const T &b) { a = min(a, b); }
/////////////////////////////////////////////////////////////////////
int main() {
fast int n, i, j;
long double p[3000], ans = 0;
long double dp[3000][3000] = {0};
cin >> n;
dp[0][0] = 1;
dp[0][1] = 0;
for (i = 1; i <= n; i++) {
cin >> p[i];
dp[i][0] = dp[i - 1][0] * (1 - p[i]);
}
// for (i = 0; i < n; i++)
// cout << p[i] << " ";
for (i = 0; i <= n; i++) {
for (j = 1; j <= i; j++) {
dp[i][j] = p[i] * dp[i - 1][j - 1] + (1 - p[i]) * dp[i - 1][j];
}
}
// for (i = 0; i <= n; i++)
// {
// for (j = 0; j <= n; j++)
// {
// cout << dp[i][j] << " ";
// }
// cout << END;
// }
for (i = 0; i <= n; i++) {
if (i > (n / 2)) {
ans += dp[n][i];
}
}
cout << setprecision(10);
cout << ans << endl;
return 0;
} | replace | 56 | 57 | 56 | 57 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 5;
double dp[MAXN][MAXN], p[MAXN];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> p[i];
dp[0][0] = 1.0;
for (int i = 1; i <= n; i++) {
for (int h = 0; h <= n; h++) {
dp[i][h] = (1.0 - p[i]) * dp[i - 1][h];
if (h > 0)
dp[i][h] += p[i] * dp[i - 1][h - 1];
}
}
double ans = 0;
for (int i = n / 2 + 1; i <= n; i++)
ans += dp[n][i];
cout << fixed << setprecision(20) << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e3 + 5;
double dp[MAXN][MAXN], p[MAXN];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> p[i];
dp[0][0] = 1.0;
for (int i = 1; i <= n; i++) {
for (int h = 0; h <= n; h++) {
dp[i][h] = (1.0 - p[i]) * dp[i - 1][h];
if (h > 0)
dp[i][h] += p[i] * dp[i - 1][h - 1];
}
}
double ans = 0;
for (int i = n / 2 + 1; i <= n; i++)
ans += dp[n][i];
cout << fixed << setprecision(20) << ans << endl;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int M = 2e3 + 4;
double dp[M][M], p[M], ans;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> p[i];
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0)
dp[i][j] = dp[i - 1][j] * (1 - p[i]);
else
dp[i][j] = dp[i - 1][j] * (1 - p[i]) + dp[i - 1][j - 1] * p[i];
}
}
for (int i = 0; i <= n; i++) {
if (i > (n - i))
ans += dp[n][i];
}
cout << fixed << setprecision(10);
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int M = 3e3 + 4;
double dp[M][M], p[M], ans;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> p[i];
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0)
dp[i][j] = dp[i - 1][j] * (1 - p[i]);
else
dp[i][j] = dp[i - 1][j] * (1 - p[i]) + dp[i - 1][j - 1] * p[i];
}
}
for (int i = 0; i <= n; i++) {
if (i > (n - i))
ans += dp[n][i];
}
cout << fixed << setprecision(10);
cout << ans;
return 0;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p03168 | C++ | Time Limit Exceeded |
// ~/SolverToBe/Developers/Corvus
// ~/sudo apt-get verdict Accpeted
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 3005, M = 1000005;
const ll MOD = 1e9 + 7;
const double eps = 1e-9;
int n;
double p[N], dp[N][N];
double calc(int i, int j) {
if (i == n)
return (j > n - j ? 1.0 : 0.0);
double &r = dp[i][j];
if (r > eps)
return r;
r = calc(i + 1, j + 1) * p[i];
r += calc(i + 1, j) * (1.0 - p[i]);
return r;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%lf", p + i);
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++)
dp[i][j] = -100;
printf("%.9lf\n", calc(0, 0));
return 0;
} |
// ~/SolverToBe/Developers/Corvus
// ~/sudo apt-get verdict Accpeted
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 3005, M = 1000005;
const ll MOD = 1e9 + 7;
const double eps = 1e-9;
int n;
double p[N], dp[N][N];
double calc(int i, int j) {
if (i == n)
return (j > n - j ? 1.0 : 0.0);
double &r = dp[i][j];
if (r > -1)
return r;
r = calc(i + 1, j + 1) * p[i];
r += calc(i + 1, j) * (1.0 - p[i]);
return r;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%lf", p + i);
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++)
dp[i][j] = -100;
printf("%.9lf\n", calc(0, 0));
return 0;
} | replace | 41 | 42 | 41 | 42 | TLE | |
p03168 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep2(i, a, b) for (ll i = a; i < b; i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()
#define INF (ll)1e9 + 7
#define LLINF (ll)1e30
// #define int ll
using namespace std;
const int MOD = 1e9 + 7;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
vector<double> p;
double dp[301][301];
dp[0][0] = 1.0;
cin >> n;
p.resize(n);
rep(i, n) cin >> p[i];
rep(i, n) {
rep(j, i + 1) {
dp[i + 1][j + 1] += dp[i][j] * p[i];
dp[i + 1][j] += dp[i][j] * (1.0 - p[i]);
}
}
double ans = 0.0;
for (int i = (n + 1) / 2; i <= n; i++) {
ans += dp[n][i];
}
cout << fixed << setprecision(10) << ans << endl;
return 0;
} | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep2(i, a, b) for (ll i = a; i < b; i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()
#define INF (ll)1e9 + 7
#define LLINF (ll)1e30
// #define int ll
using namespace std;
const int MOD = 1e9 + 7;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
vector<double> p;
double dp[3010][3010];
dp[0][0] = 1.0;
cin >> n;
p.resize(n);
rep(i, n) cin >> p[i];
rep(i, n) {
rep(j, i + 1) {
dp[i + 1][j + 1] += dp[i][j] * p[i];
dp[i + 1][j] += dp[i][j] * (1.0 - p[i]);
}
}
double ans = 0.0;
for (int i = (n + 1) / 2; i <= n; i++) {
ans += dp[n][i];
}
cout << fixed << setprecision(10) << ans << endl;
return 0;
}
| replace | 38 | 39 | 38 | 39 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 4;
#define ll long long
long double p[MAXN], dp[MAXN][MAXN];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> p[i];
dp[0][0] = 1;
for (int i = 1; i <= n; i++)
for (int j = 0; j <= i; j++) {
if (j)
dp[i][j] += dp[i - 1][j - 1] * p[i - 1];
dp[i][j] += dp[i - 1][j] * (1 - p[i - 1]);
}
long double R = 0;
for (int i = 0; i <= n; i++)
if (i > n - i)
R += dp[n][i];
cout << fixed << setprecision(10) << R;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e3 + 4;
#define ll long long
long double p[MAXN], dp[MAXN][MAXN];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> p[i];
dp[0][0] = 1;
for (int i = 1; i <= n; i++)
for (int j = 0; j <= i; j++) {
if (j)
dp[i][j] += dp[i - 1][j - 1] * p[i - 1];
dp[i][j] += dp[i - 1][j] * (1 - p[i - 1]);
}
long double R = 0;
for (int i = 0; i <= n; i++)
if (i > n - i)
R += dp[n][i];
cout << fixed << setprecision(10) << R;
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef long double lld;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define sortvec(a) sort(a.begin(), a.end())
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
#define cerr \
if (true) \
cerr
void print() { cout << endl; }
template <typename T, typename... Args> void print(T a, Args... args) {
cout << a << " ";
print(args...);
}
lli llipowerp(lli x, lli y, lli p = LLONG_MAX) {
lli res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
lli binarySearch(vector<int> arr, int l, int r, int x) {
if (r >= l) {
lli mid = l + (r - l) / 2;
if (arr[mid] == x)
return mid;
if (arr[mid] > x)
return binarySearch(arr, l, mid - 1, x);
return binarySearch(arr, mid + 1, r, x);
}
return -1;
}
template <typename T> inline void printvec(vector<T> inp) {
for (auto it : inp)
cout << it << " ";
cout << endl;
}
//---------------------------------------------------------------------------------
int n;
lld dp[3010][3010];
vector<lld> p(1010);
lld fill(int i, int j) {
if (i + j > n)
return 0;
if (i < 0 || j < 0)
return 0;
if (dp[i][j] != -1)
return dp[i][j];
dp[i][j] = fill(i - 1, j) * p[i + j] + fill(i, j - 1) * (1 - p[i + j]);
return dp[i][j];
}
int main() {
cin >> n;
fori(n + 1) { forj(n + 1) dp[i][j] = -1; }
fori(n) cin >> p[i + 1];
dp[0][0] = 1;
lld ans = 0;
for (int tails = 0; tails <= n; tails++) {
if (n - tails > tails)
ans += fill(n - tails, tails);
}
cout << fixed << setprecision(12) << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef long double lld;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define sortvec(a) sort(a.begin(), a.end())
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
#define cerr \
if (true) \
cerr
void print() { cout << endl; }
template <typename T, typename... Args> void print(T a, Args... args) {
cout << a << " ";
print(args...);
}
lli llipowerp(lli x, lli y, lli p = LLONG_MAX) {
lli res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
lli binarySearch(vector<int> arr, int l, int r, int x) {
if (r >= l) {
lli mid = l + (r - l) / 2;
if (arr[mid] == x)
return mid;
if (arr[mid] > x)
return binarySearch(arr, l, mid - 1, x);
return binarySearch(arr, mid + 1, r, x);
}
return -1;
}
template <typename T> inline void printvec(vector<T> inp) {
for (auto it : inp)
cout << it << " ";
cout << endl;
}
//---------------------------------------------------------------------------------
int n;
lld dp[3010][3010];
vector<lld> p(3010);
lld fill(int i, int j) {
if (i + j > n)
return 0;
if (i < 0 || j < 0)
return 0;
if (dp[i][j] != -1)
return dp[i][j];
dp[i][j] = fill(i - 1, j) * p[i + j] + fill(i, j - 1) * (1 - p[i + j]);
return dp[i][j];
}
int main() {
cin >> n;
fori(n + 1) { forj(n + 1) dp[i][j] = -1; }
fori(n) cin >> p[i + 1];
dp[0][0] = 1;
lld ans = 0;
for (int tails = 0; tails <= n; tails++) {
if (n - tails > tails)
ans += fill(n - tails, tails);
}
cout << fixed << setprecision(12) << ans << endl;
} | replace | 54 | 55 | 54 | 55 | -11 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define start_routine() int begtime = clock();
#define end_routine() \
int endtime = clock(); \
cerr << "\n\n" \
<< "Time elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC \
<< " ms\n\n"; \
return 0
#define ll long long int
#define ull unsigned long long int
#define db long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define pdd pair<db, db>
#define pll pair<ll, ll>
#define vpl vector<pll>
#define vll vector<ll>
#define mod 1000000007
#define inf 100000000000000007
#define eps 0.000001
#define stp fixed << setprecision(20)
#define endl '\n'
db dp[3005][3005];
db ans;
int main() {
start_routine();
fastio;
ll n;
cin >> n;
db p[n + 1];
for (ll i = 1; i <= n; i++)
cin >> p[i];
dp[0][0] = 1;
for (ll i = 1; i <= n; i++) {
dp[i][0] = dp[i - 1][0] * p[i];
dp[0][i] = dp[0][i - 1] * (1.0 - p[i]);
}
for (ll i = 1; i <= n; i++)
for (ll j = 1; j <= n; j++)
dp[i][j] = (dp[i][j - 1] * (1.0 - p[i + j])) + (dp[i - 1][j] * p[i + j]);
for (ll i = 0; i <= n; i++)
for (ll j = 0; j <= n; j++)
if (i > j && i + j == n)
ans += dp[i][j];
cout << stp << ans;
end_routine();
} | #include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define start_routine() int begtime = clock();
#define end_routine() \
int endtime = clock(); \
cerr << "\n\n" \
<< "Time elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC \
<< " ms\n\n"; \
return 0
#define ll long long int
#define ull unsigned long long int
#define db long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define pdd pair<db, db>
#define pll pair<ll, ll>
#define vpl vector<pll>
#define vll vector<ll>
#define mod 1000000007
#define inf 100000000000000007
#define eps 0.000001
#define stp fixed << setprecision(20)
#define endl '\n'
db dp[3005][3005];
db ans;
int main() {
start_routine();
fastio;
ll n;
cin >> n;
db p[n + 1];
for (ll i = 1; i <= n; i++)
cin >> p[i];
dp[0][0] = 1;
for (ll i = 1; i <= n; i++) {
dp[i][0] = dp[i - 1][0] * p[i];
dp[0][i] = dp[0][i - 1] * (1.0 - p[i]);
}
for (ll i = 1; i <= n; i++)
for (ll j = 1; j <= n; j++)
if (i + j <= n)
dp[i][j] =
(dp[i][j - 1] * (1.0 - p[i + j])) + (dp[i - 1][j] * p[i + j]);
for (ll i = 0; i <= n; i++)
for (ll j = 0; j <= n; j++)
if (i > j && i + j == n)
ans += dp[i][j];
cout << stp << ans;
end_routine();
} | replace | 55 | 56 | 55 | 58 | -11 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define fr(i, a, b) for (int i = a; i < b; i++)
#define mod 1000000007
#define fr(i, a, b) for (int i = a; i < b; i++)
double dp[3001][3001];
double solve(vector<double> &ar, int i, int x) {
if (x == 0) {
return 1;
}
if (i == 0) {
return 0;
}
if (dp[i][x] > -0.9)
return dp[i][x];
return dp[i][x] = ar[i] * solve(ar, i - 1, x - 1) +
(1 - ar[i]) * solve(ar, i - 1, x);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
memset(dp, -1, sizeof(dp));
vector<double> ar(n + 1);
fr(i, 1, n + 1) cin >> ar[i];
cout << fixed << setprecision(10) << solve(ar, n, (n + 1) / 2);
} | #include <bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define fr(i, a, b) for (int i = a; i < b; i++)
#define mod 1000000007
#define fr(i, a, b) for (int i = a; i < b; i++)
double dp[3001][3001];
double solve(vector<double> &ar, int i, int x) {
if (x == 0) {
return 1;
}
if (i == 0) {
return 0;
}
if (dp[i][x] > -0.9)
return dp[i][x];
return dp[i][x] = ar[i] * solve(ar, i - 1, x - 1) +
(1 - ar[i]) * solve(ar, i - 1, x);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
memset(dp, -1, sizeof(dp));
vector<double> ar(n + 1);
fr(i, 1, n + 1) cin >> ar[i];
cout << fixed << setprecision(10) << solve(ar, n, (n + 1) / 2);
} | delete | 30 | 34 | 30 | 30 | -6 | terminate called after throwing an instance of 'std::length_error'
what(): cannot create std::vector larger than max_size()
|
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define forin(i, a, b) for (int i = a; i < (int)b; i++)
#define rofin(i, a, b) for (int i = a; i > b; i--)
#define v vector
#define crap \
ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define debug(i) cout << #i << ": " << i << endl
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
int main() {
crap;
int N;
cin >> N;
vector<ld> p(N);
vector<vector<ld>> dp(N + 1, vector<ld>(N + 1));
for (int i = 1; i <= N; i++)
cin >> p[i];
dp[0][0] = 1;
for (int i = 1; i <= N; i++) { // i: total number of coins tossed so far
for (int j = 0; j <= i; j++) { // j: number of heads so far
if (j == 0) {
dp[i][j] = dp[i - 1][j] * (1 - p[i]);
} else if (j == i) {
dp[i][j] = dp[i - 1][j - 1] * p[i];
} else {
dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]);
}
}
}
ld sol = 0;
for (int i = N; i > N / 2; i--) {
sol += dp[N][i];
}
cout << setprecision(10) << sol << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define forin(i, a, b) for (int i = a; i < (int)b; i++)
#define rofin(i, a, b) for (int i = a; i > b; i--)
#define v vector
#define crap \
ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define debug(i) cout << #i << ": " << i << endl
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
int main() {
crap;
int N;
cin >> N;
vector<ld> p(N + 1);
vector<vector<ld>> dp(N + 1, vector<ld>(N + 1));
for (int i = 1; i <= N; i++)
cin >> p[i];
dp[0][0] = 1;
for (int i = 1; i <= N; i++) { // i: total number of coins tossed so far
for (int j = 0; j <= i; j++) { // j: number of heads so far
if (j == 0) {
dp[i][j] = dp[i - 1][j] * (1 - p[i]);
} else if (j == i) {
dp[i][j] = dp[i - 1][j - 1] * p[i];
} else {
dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]);
}
}
}
ld sol = 0;
for (int i = N; i > N / 2; i--) {
sol += dp[N][i];
}
cout << setprecision(10) << sol << endl;
} | replace | 20 | 21 | 20 | 21 | -6 | munmap_chunk(): invalid pointer
|
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
// #define mp make_pair
#define eb emplace_back
#define pb push_back
#define ss second
#define ff first
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define mod 998244353
#define MOD (1000 * 1000 * 1000 + 7)
#define MN LLONG_MIN
#define MX LLONG_MAX
#define v1d vector<int>
#define v2d vector<vector<int>>
#define vip vector<pair<int, int>>
#define v1s vector<string>
#define pa pair<int, int>
#define mxpq(T) priority_queue<T>
#define mnpq(T) priority_queue<T, vector<T>, greater<T>>
#define print(v) \
for (auto i : v) \
cout << i << " "; \
cout << "\n";
#define p2d(v) \
for (auto a : v) { \
for (auto b : a) \
cout << b << " "; \
cout << endl; \
}
#define p1d(v) \
for (auto a : v) \
cout << a << " "; \
cout << endl;
#define ppd(v) \
for (auto a : v) \
cout << a.ff << " " << a.ss << endl;
#define endl "\n"
#define input(b, n) \
for (int i = 0; i < n; i++) \
cin >> b[i + 1];
#define Sort(v) sort(v.begin(), v.end())
#define RSort(v) sort(v.rbegin(), v.rend())
#define all(v) v.begin(), v.end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// string s = bitset<64>(a).to_string();
void azmuth(int n = 12) {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << setprecision(n) << fixed;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int lb = 10000000;
//____________________________________________________________________________________
int n;
vector<double> p;
vector<vector<double>> dp;
double fun(int idx, int head) {
if (idx > n) {
if (head >= (n + 1) / 2)
return 1.0;
else
return 0;
}
if (dp[idx][head] != -1)
return dp[idx][head];
double a = p[idx] * fun(idx + 1, head + 1);
double b = (1 - p[idx]) * fun(idx + 1, head);
return dp[idx][head] = a + b;
}
void solve() {
cin >> n;
dp.resize(n + 1, vector<double>(n + 1, -1));
p.resize(n + 1);
for (int i = 1; i <= n; i++)
cin >> p[i];
cout << fixed << fun(0, 0);
}
int32_t main() {
azmuth();
int t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
// #define mp make_pair
#define eb emplace_back
#define pb push_back
#define ss second
#define ff first
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define mod 998244353
#define MOD (1000 * 1000 * 1000 + 7)
#define MN LLONG_MIN
#define MX LLONG_MAX
#define v1d vector<int>
#define v2d vector<vector<int>>
#define vip vector<pair<int, int>>
#define v1s vector<string>
#define pa pair<int, int>
#define mxpq(T) priority_queue<T>
#define mnpq(T) priority_queue<T, vector<T>, greater<T>>
#define print(v) \
for (auto i : v) \
cout << i << " "; \
cout << "\n";
#define p2d(v) \
for (auto a : v) { \
for (auto b : a) \
cout << b << " "; \
cout << endl; \
}
#define p1d(v) \
for (auto a : v) \
cout << a << " "; \
cout << endl;
#define ppd(v) \
for (auto a : v) \
cout << a.ff << " " << a.ss << endl;
#define endl "\n"
#define input(b, n) \
for (int i = 0; i < n; i++) \
cin >> b[i + 1];
#define Sort(v) sort(v.begin(), v.end())
#define RSort(v) sort(v.rbegin(), v.rend())
#define all(v) v.begin(), v.end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// string s = bitset<64>(a).to_string();
void azmuth(int n = 12) {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << setprecision(n) << fixed;
}
int lb = 10000000;
//____________________________________________________________________________________
int n;
vector<double> p;
vector<vector<double>> dp;
double fun(int idx, int head) {
if (idx > n) {
if (head >= (n + 1) / 2)
return 1.0;
else
return 0;
}
if (dp[idx][head] != -1)
return dp[idx][head];
double a = p[idx] * fun(idx + 1, head + 1);
double b = (1 - p[idx]) * fun(idx + 1, head);
return dp[idx][head] = a + b;
}
void solve() {
cin >> n;
dp.resize(n + 1, vector<double>(n + 1, -1));
p.resize(n + 1);
for (int i = 1; i <= n; i++)
cin >> p[i];
cout << fixed << fun(0, 0);
}
int32_t main() {
azmuth();
int t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
} | delete | 56 | 60 | 56 | 56 | 0 | |
p03168 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> isPair;
using vvll = vector<vector<ll>>;
using vll = vector<ll>;
#define Pll pair<ll, ll>
#define vpll vector<pll>
#define sll set<ll>
#define mll map<ll, ll>
const ll inf = 1e18;
const ll maxs = 100005;
const ll mod = 1e9 + 7;
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define LB lower_bound
#define UB upper_bound
#define line cout << endl;
#define fr(i, a, b) for (int i = a; i <= b; ++i)
#define all(n) n.begin(), n.end()
#define present(s, x) (s.find(x) != s.end())
#define cpresent(s, x) (find(all(s), x) != s.end())
#define tr(container, it) \
for (__typeof(container.begin()) it = container.begin(); \
it != container.end(); it++)
#define fastio() \
; \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define mst(x, a) memset(x, a, sizeof(x))
ll n;
double dp[3000][3000];
double p[3000];
double go(ll pos, ll h, ll t) {
if (pos == n)
return h > t;
if (dp[pos][h] != -1)
return dp[pos][h];
double ans = 0;
ans += p[pos] * go(pos + 1, h + 1, t);
ans += (1 - p[pos]) * go(pos + 1, h, t + 1);
return ans;
}
int main() {
fastio();
cout.precision(20);
cout << fixed;
ll t = 1;
// cin>>t;
while (t--) {
for (ll i = 0; i < 3000; i++) {
for (ll j = 0; j < 3000; j++)
dp[i][j] = -1;
}
cin >> n;
for (ll i = 0; i < n; i++)
cin >> p[i];
cout << go(0, 0, 0);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> isPair;
using vvll = vector<vector<ll>>;
using vll = vector<ll>;
#define Pll pair<ll, ll>
#define vpll vector<pll>
#define sll set<ll>
#define mll map<ll, ll>
const ll inf = 1e18;
const ll maxs = 100005;
const ll mod = 1e9 + 7;
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define LB lower_bound
#define UB upper_bound
#define line cout << endl;
#define fr(i, a, b) for (int i = a; i <= b; ++i)
#define all(n) n.begin(), n.end()
#define present(s, x) (s.find(x) != s.end())
#define cpresent(s, x) (find(all(s), x) != s.end())
#define tr(container, it) \
for (__typeof(container.begin()) it = container.begin(); \
it != container.end(); it++)
#define fastio() \
; \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define mst(x, a) memset(x, a, sizeof(x))
ll n;
double dp[3000][3000];
double p[3000];
double go(ll pos, ll h, ll t) {
if (pos == n)
return h > t;
if (dp[pos][h] != -1)
return dp[pos][h];
double ans = 0;
ans += p[pos] * go(pos + 1, h + 1, t);
ans += (1 - p[pos]) * go(pos + 1, h, t + 1);
return dp[pos][h] = ans;
}
int main() {
fastio();
cout.precision(20);
cout << fixed;
ll t = 1;
// cin>>t;
while (t--) {
for (ll i = 0; i < 3000; i++) {
for (ll j = 0; j < 3000; j++)
dp[i][j] = -1;
}
cin >> n;
for (ll i = 0; i < n; i++)
cin >> p[i];
cout << go(0, 0, 0);
}
return 0;
} | replace | 57 | 58 | 57 | 58 | TLE | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
long double prob[3000];
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
long double p;
prob[0] = 1;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> p;
for (int j = 2 * n; j >= 1; j--) {
prob[j] = prob[j] * (1 - p) + prob[j - 1] * p;
}
prob[0] = prob[0] * (1 - p);
}
long double ans = 0;
for (int i = 1 + n / 2; i <= n; i++)
ans += prob[i];
cout << fixed << setprecision(10) << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
long double prob[3000];
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
long double p;
prob[0] = 1;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> p;
for (int j = n; j >= 1; j--) {
prob[j] = prob[j] * (1 - p) + prob[j - 1] * p;
}
prob[0] = prob[0] * (1 - p);
}
long double ans = 0;
for (int i = 1 + n / 2; i <= n; i++)
ans += prob[i];
cout << fixed << setprecision(10) << ans;
return 0;
} | replace | 13 | 14 | 13 | 14 | 0 | |
p03168 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
#define PI 3.141592653589
#define IO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define EPS 1e-7
#define f first
#define s second
using namespace std;
int n;
double p[3000];
double memo[3000][3000];
double solve(int heads, int tails) {
if (heads + tails == n)
return (heads > tails) * 1.0;
double &res = memo[heads][tails];
if (res > 0)
return res;
return res = (p[heads + tails]) * solve(heads + 1, tails) +
(1 - p[heads + tails]) * solve(heads, tails + 1);
}
int main() {
IO;
memset(memo, -1.0, sizeof memo);
cin >> n;
for (int i = 0; i < n; ++i)
cin >> p[i];
cout << fixed << setprecision(10) << solve(0, 0);
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define PI 3.141592653589
#define IO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define EPS 1e-7
#define f first
#define s second
using namespace std;
int n;
double p[3000];
double memo[3000][3000];
double solve(int heads, int tails) {
if (heads + tails == n)
return (heads > tails) * 1.0;
double &res = memo[heads][tails];
if (res >= 0)
return res;
return res = (p[heads + tails]) * solve(heads + 1, tails) +
(1 - p[heads + tails]) * solve(heads, tails + 1);
}
int main() {
IO;
memset(memo, -1.0, sizeof memo);
cin >> n;
for (int i = 0; i < n; ++i)
cin >> p[i];
cout << fixed << setprecision(10) << solve(0, 0);
return 0;
}
| replace | 18 | 19 | 18 | 19 | TLE | |
p03168 | C++ | Runtime Error | // if acyclic graph try toposort
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define vll vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll, ll>
#define fo(i, n) for (ll i = 0; i < n; i++)
#define foa(i, s, e) for (ll i = (s); i < e; i++)
#define fod(i, s, e) for (ll i = (s); i >= (e); i--)
#define max3(a, b, c) max(max(a, b), c)
#define min3(a, b, c) min(min(a, b), c)
#define deb(x) cerr << #x << ' ' << '=' << ' ' << x << '\n'
#define sz(x) (ll)(x.size())
#define ANS cout << ans << '\n'
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define Yes cout << "Yes\n"
#define No cout << "No\n"
const ld pi = 3.14159265358979323846;
ll MOD = 1e9 + 7;
// ll MOD = 998244353;
const char nl = '\n';
const ll inf = 1e15;
#define fill(a, b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp, n, m) \
fo(i, n) { \
fo(j, m) cout << dp[i][j] << " "; \
cout << "\n"; \
}
template <typename T> void umax(T &a, T b) { a = max(a, b); }
template <typename T> void umin(T &a, T b) { a = min(a, b); }
ll nxt() {
ll x;
cin >> x;
return x;
}
ll mul(ll x, ll y) { return (1ll * (x % MOD) * (y % MOD)); }
ll modpow(ll x, ll y) {
ll z = 1;
while (y > 0) {
if (y % 2)
z = mul(z, x);
x = mul(x, x);
y /= 2;
}
return z;
}
ll power(ll x, ll y) {
ll z = 1;
while (y > 0) {
if (y % 2)
z = z * x;
x = x * x;
y /= 2;
}
return z;
}
ll gcd(ll a, ll b) {
if (a < b)
return gcd(b, a);
if (b == 0)
return a;
return gcd(b, a % b);
}
ll sq(ll a) {
ll ans = (1ll * a * a);
return ans;
}
const ll N = 1e3 + 5;
ld dp[N];
void solve() {
ll n;
cin >> n;
dp[0] = 1;
fo(i, n) {
ld p;
cin >> p;
for (ll j = i + 1; j >= 0; j--) {
dp[j] = dp[j] * (1 - p) + (j ? dp[j - 1] * p : 0);
}
}
// fo(i, n)cout << dp[i] << nl;
ld ans = 0;
fo(i, n + 1) {
ll t = n - i;
if (t < i) {
ans += dp[i];
}
}
cout << fixed << setprecision(10) << ans << nl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("inputf.txt", "r", stdin);
freopen("outputf.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
ll TC = 1;
// cin>>TC;
while (TC--) {
solve();
}
cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
<< "ms\n";
}
| // if acyclic graph try toposort
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define vll vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll, ll>
#define fo(i, n) for (ll i = 0; i < n; i++)
#define foa(i, s, e) for (ll i = (s); i < e; i++)
#define fod(i, s, e) for (ll i = (s); i >= (e); i--)
#define max3(a, b, c) max(max(a, b), c)
#define min3(a, b, c) min(min(a, b), c)
#define deb(x) cerr << #x << ' ' << '=' << ' ' << x << '\n'
#define sz(x) (ll)(x.size())
#define ANS cout << ans << '\n'
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define Yes cout << "Yes\n"
#define No cout << "No\n"
const ld pi = 3.14159265358979323846;
ll MOD = 1e9 + 7;
// ll MOD = 998244353;
const char nl = '\n';
const ll inf = 1e15;
#define fill(a, b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp, n, m) \
fo(i, n) { \
fo(j, m) cout << dp[i][j] << " "; \
cout << "\n"; \
}
template <typename T> void umax(T &a, T b) { a = max(a, b); }
template <typename T> void umin(T &a, T b) { a = min(a, b); }
ll nxt() {
ll x;
cin >> x;
return x;
}
ll mul(ll x, ll y) { return (1ll * (x % MOD) * (y % MOD)); }
ll modpow(ll x, ll y) {
ll z = 1;
while (y > 0) {
if (y % 2)
z = mul(z, x);
x = mul(x, x);
y /= 2;
}
return z;
}
ll power(ll x, ll y) {
ll z = 1;
while (y > 0) {
if (y % 2)
z = z * x;
x = x * x;
y /= 2;
}
return z;
}
ll gcd(ll a, ll b) {
if (a < b)
return gcd(b, a);
if (b == 0)
return a;
return gcd(b, a % b);
}
ll sq(ll a) {
ll ans = (1ll * a * a);
return ans;
}
const ll N = 3e3 + 5;
ld dp[N];
void solve() {
ll n;
cin >> n;
dp[0] = 1;
fo(i, n) {
ld p;
cin >> p;
for (ll j = i + 1; j >= 0; j--) {
dp[j] = dp[j] * (1 - p) + (j ? dp[j - 1] * p : 0);
}
}
// fo(i, n)cout << dp[i] << nl;
ld ans = 0;
fo(i, n + 1) {
ll t = n - i;
if (t < i) {
ans += dp[i];
}
}
cout << fixed << setprecision(10) << ans << nl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("inputf.txt", "r", stdin);
freopen("outputf.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
ll TC = 1;
// cin>>TC;
while (TC--) {
solve();
}
cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
<< "ms\n";
}
| replace | 81 | 82 | 81 | 82 | -11 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 2010;
int n;
double p[N], f[N][N] = {1.0}; // f[i][j]表示前i个硬币中j个正面向上的概率
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%lf", &p[i]);
f[i][0] = f[i - 1][0] * (1.0 - p[i]);
for (int j = 1; j <= i; j++)
f[i][j] = f[i - 1][j - 1] * p[i] + f[i - 1][j] * (1.0 - p[i]);
}
double ans = 0.0;
for (int i = (n >> 1) + 1; i <= n; i++)
ans += f[n][i];
printf("%.10lf\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 3010;
int n;
double p[N], f[N][N] = {1.0}; // f[i][j]表示前i个硬币中j个正面向上的概率
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%lf", &p[i]);
f[i][0] = f[i - 1][0] * (1.0 - p[i]);
for (int j = 1; j <= i; j++)
f[i][j] = f[i - 1][j - 1] * p[i] + f[i - 1][j] * (1.0 - p[i]);
}
double ans = 0.0;
for (int i = (n >> 1) + 1; i <= n; i++)
ans += f[n][i];
printf("%.10lf\n", ans);
return 0;
}
| replace | 2 | 3 | 2 | 3 | 0 | |
p03168 | C++ | Runtime Error | /*
Created by Rishu Sahu @ covid 20-20
*/
/*
*****************************************************************
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS \
cin.sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define ll long long int
#define pai pair<int, int>
#define pal pair<ll, ll>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, a, b) for (int i = a; i <= b; i++)
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define vi vector<int>
#define vl vector<ll>
#define mpl map<ll, ll>
#define mpi map<int, int>
#define pb push_back
#define all(x) x.begin(), x.end()
const int mod = 1e9 + 7;
const int INF = INT_MAX;
const int sze = 1005;
double dp[sze][sze];
void solve() {
int n;
cin >> n;
double head[n + 1];
double tail[n + 1];
rep(i, n) {
cin >> head[i + 1];
tail[i + 1] = 1.0 - head[i + 1];
}
memset(dp, 0, sizeof(dp));
dp[0][0] = 1.0;
for (int i = 1; i <= n; i++) {
dp[i][0] = tail[i] * dp[i - 1][0];
for (int j = 1; j <= i; j++) {
dp[i][j] = head[i] * dp[i - 1][j - 1] + tail[i] * dp[i - 1][j];
}
}
double ans = 0;
for (int i = n / 2 + 1; i <= n; i++)
ans += dp[n][i];
cout << fixed << setprecision(10) << ans << endl;
}
int main() { solve(); }
| /*
Created by Rishu Sahu @ covid 20-20
*/
/*
*****************************************************************
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS \
cin.sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define ll long long int
#define pai pair<int, int>
#define pal pair<ll, ll>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, a, b) for (int i = a; i <= b; i++)
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define vi vector<int>
#define vl vector<ll>
#define mpl map<ll, ll>
#define mpi map<int, int>
#define pb push_back
#define all(x) x.begin(), x.end()
const int mod = 1e9 + 7;
const int INF = INT_MAX;
const int sze = 3005;
double dp[sze][sze];
void solve() {
int n;
cin >> n;
double head[n + 1];
double tail[n + 1];
rep(i, n) {
cin >> head[i + 1];
tail[i + 1] = 1.0 - head[i + 1];
}
memset(dp, 0, sizeof(dp));
dp[0][0] = 1.0;
for (int i = 1; i <= n; i++) {
dp[i][0] = tail[i] * dp[i - 1][0];
for (int j = 1; j <= i; j++) {
dp[i][j] = head[i] * dp[i - 1][j - 1] + tail[i] * dp[i - 1][j];
}
}
double ans = 0;
for (int i = n / 2 + 1; i <= n; i++)
ans += dp[n][i];
cout << fixed << setprecision(10) << ans << endl;
}
int main() { solve(); }
| replace | 31 | 32 | 31 | 32 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
// For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test \
int t; \
cin >> t; \
while (t--)
#define init(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, a, b) for (int i = a; i < b; i++)
#define loopr(i, a, b) for (int i = a; i >= b; i--)
#define loops(i, a, b, step) for (int i = a; i < b; i += step)
#define looprs(i, a, b, step) for (int i = a; i >= b; i -= step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(); \
cout.tie();
#define FILE_READ_IN freopen("input.txt", "r", stdin);
#define FILE_READ_OUT freopen("output.txt", "w", stdout);
#define all(a) a.begin(), a.end()
#define ld long double
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);
int main() {
ll n;
cin >> n;
ld A[n];
loop(i, 0, n) { cin >> A[i]; }
ld prob[100][100];
init(prob, 0);
prob[0][0] = 1.0;
loop(i, 1, n + 1) { prob[i][0] = prob[i - 1][0] * (1 - A[i - 1]); }
loop(i, 1, n + 1) {
loop(j, 1, n + 1) {
if (j > i) {
break;
}
prob[i][j] =
A[i - 1] * prob[i - 1][j - 1] + (1 - A[i - 1]) * prob[i - 1][j];
}
}
// loop(i,0,n+1){
// loop(j,0,n+1){
// cout<<prob[i][j]<<" ";
// }
// cout<<"\n";
// }
ld ans = 0;
ll mid = n / 2;
loop(j, mid + 1, n + 1) { ans += prob[n][j]; }
cout << fixed << setprecision(10) << ans << endl;
return 0;
} | #include <bits/stdc++.h>
// For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test \
int t; \
cin >> t; \
while (t--)
#define init(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, a, b) for (int i = a; i < b; i++)
#define loopr(i, a, b) for (int i = a; i >= b; i--)
#define loops(i, a, b, step) for (int i = a; i < b; i += step)
#define looprs(i, a, b, step) for (int i = a; i >= b; i -= step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(); \
cout.tie();
#define FILE_READ_IN freopen("input.txt", "r", stdin);
#define FILE_READ_OUT freopen("output.txt", "w", stdout);
#define all(a) a.begin(), a.end()
#define ld long double
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);
int main() {
ll n;
cin >> n;
ld A[n];
loop(i, 0, n) { cin >> A[i]; }
ld prob[3000][3000];
init(prob, 0);
prob[0][0] = 1.0;
loop(i, 1, n + 1) { prob[i][0] = prob[i - 1][0] * (1 - A[i - 1]); }
loop(i, 1, n + 1) {
loop(j, 1, n + 1) {
if (j > i) {
break;
}
prob[i][j] =
A[i - 1] * prob[i - 1][j - 1] + (1 - A[i - 1]) * prob[i - 1][j];
}
}
// loop(i,0,n+1){
// loop(j,0,n+1){
// cout<<prob[i][j]<<" ";
// }
// cout<<"\n";
// }
ld ans = 0;
ll mid = n / 2;
loop(j, mid + 1, n + 1) { ans += prob[n][j]; }
cout << fixed << setprecision(10) << ans << endl;
return 0;
} | replace | 57 | 58 | 57 | 58 | 0 | |
p03168 | C++ | Runtime Error | #pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
#define left(x) (x << 1)
#define right(x) (x << 1) + 1
#define mid(l, r) ((l + r) >> 1)
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define debug(x) \
{ cerr << #x << " = " << x << "\n"; }
#define debug2(x, y) \
{ cerr << #x << " = " << x << ", " << #y << " = " << y << "\n"; }
#define debug3(x, y, z) \
{ \
cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z \
<< " = " << z << "\n"; \
}
#define debug4(x, y, z, w) \
{ \
cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z \
<< " = " << z << ", " << #w << " = " << w << "\n"; \
}
#define ss second
#define ff first
#define m0(x) memset(x, 0, sizeof(x))
template <typename T> T min_(T a, T b) { return a > b ? b : a; }
template <typename T, typename... Ts> T min_(T first, Ts... last) {
return min_(first, min_(last...));
}
template <typename T> T max_(T a, T b) { return a > b ? a : b; }
template <typename T, typename... Ts> T max_(T first, Ts... last) {
return max_(first, max_(last...));
}
template <class T, class S>
std::ostream &operator<<(std::ostream &os, const std::pair<T, S> &t) {
os << "(" << t.first << ", " << t.second << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
out << "[";
size_t last = v.size() - 1;
for (size_t i = 0; i < v.size(); ++i) {
out << v[i];
if (i != last)
out << ", ";
}
out << "]";
return out;
}
ll pwr(ll base, ll p, ll mod) {
ll ans = 1;
while (p) {
if (p & 1)
ans = (ans * base) % mod;
base = (base * base) % mod;
p /= 2;
}
return ans;
}
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const long double PI = (long double)(3.1415926535897932384626433832795);
const ll mx_ll = numeric_limits<ll>::max();
const int mx_int = numeric_limits<int>::max();
const int mod = 1e9 + 7;
const int maxn = 2e5 + 7;
void cppio() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
double dp[1001][1001];
void solve() {
int n;
cin >> n;
vector<double> p(n + 1);
for (int i = 0; i < n; i++) {
cin >> p[i + 1];
}
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int h = 0; h <= i; h++) {
dp[i][h] =
((h == 0) ? 0 : dp[i - 1][h - 1] * p[i]) + dp[i - 1][h] * (1 - p[i]);
}
}
double ans = 0;
for (int h = 0; h <= n; h++) {
if (h > (n - h))
ans += dp[n][h];
}
cout << setprecision(10) << fixed << ans << "\n";
}
int main() {
cppio();
#ifdef __APPLE__
// freopen("test.in", "rb", stdin);
// freopen(" .out", "wb", stdout);
#endif
int num_test_cases = 1;
// cin >> num_test_cases;
for (int t = 1; t <= num_test_cases; ++t) {
solve();
}
return 0;
}
| #pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
#define left(x) (x << 1)
#define right(x) (x << 1) + 1
#define mid(l, r) ((l + r) >> 1)
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define debug(x) \
{ cerr << #x << " = " << x << "\n"; }
#define debug2(x, y) \
{ cerr << #x << " = " << x << ", " << #y << " = " << y << "\n"; }
#define debug3(x, y, z) \
{ \
cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z \
<< " = " << z << "\n"; \
}
#define debug4(x, y, z, w) \
{ \
cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z \
<< " = " << z << ", " << #w << " = " << w << "\n"; \
}
#define ss second
#define ff first
#define m0(x) memset(x, 0, sizeof(x))
template <typename T> T min_(T a, T b) { return a > b ? b : a; }
template <typename T, typename... Ts> T min_(T first, Ts... last) {
return min_(first, min_(last...));
}
template <typename T> T max_(T a, T b) { return a > b ? a : b; }
template <typename T, typename... Ts> T max_(T first, Ts... last) {
return max_(first, max_(last...));
}
template <class T, class S>
std::ostream &operator<<(std::ostream &os, const std::pair<T, S> &t) {
os << "(" << t.first << ", " << t.second << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
out << "[";
size_t last = v.size() - 1;
for (size_t i = 0; i < v.size(); ++i) {
out << v[i];
if (i != last)
out << ", ";
}
out << "]";
return out;
}
ll pwr(ll base, ll p, ll mod) {
ll ans = 1;
while (p) {
if (p & 1)
ans = (ans * base) % mod;
base = (base * base) % mod;
p /= 2;
}
return ans;
}
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const long double PI = (long double)(3.1415926535897932384626433832795);
const ll mx_ll = numeric_limits<ll>::max();
const int mx_int = numeric_limits<int>::max();
const int mod = 1e9 + 7;
const int maxn = 2e5 + 7;
void cppio() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
double dp[5001][5001];
void solve() {
int n;
cin >> n;
vector<double> p(n + 1);
for (int i = 0; i < n; i++) {
cin >> p[i + 1];
}
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int h = 0; h <= i; h++) {
dp[i][h] =
((h == 0) ? 0 : dp[i - 1][h - 1] * p[i]) + dp[i - 1][h] * (1 - p[i]);
}
}
double ans = 0;
for (int h = 0; h <= n; h++) {
if (h > (n - h))
ans += dp[n][h];
}
cout << setprecision(10) << fixed << ans << "\n";
}
int main() {
cppio();
#ifdef __APPLE__
// freopen("test.in", "rb", stdin);
// freopen(" .out", "wb", stdout);
#endif
int num_test_cases = 1;
// cin >> num_test_cases;
for (int t = 1; t <= num_test_cases; ++t) {
solve();
}
return 0;
}
| replace | 115 | 116 | 115 | 116 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
long int n;
cin >> n;
vector<double> p(n + 1, 0);
double ans[303][303];
ans[0][0] = 1;
for (long int i = 1; i <= n; i++) {
cin >> p[i];
}
for (long int i = 1; i <= n; i++) {
double head = p[i], tail = 1 - p[i];
ans[0][i] = tail * ans[0][i - 1];
for (long int h = 1; h <= i; h++) {
ans[h][i] = head * ans[h - 1][i - 1] + tail * ans[h][i - 1];
}
}
double answer = 0;
for (long int i = n / 2 + 1; i <= n; i++) {
answer = answer + ans[i][n];
}
cout << setprecision(9) << answer;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long int n;
cin >> n;
vector<double> p(n + 1, 0);
double ans[3003][3003];
ans[0][0] = 1;
for (long int i = 1; i <= n; i++) {
cin >> p[i];
}
for (long int i = 1; i <= n; i++) {
double head = p[i], tail = 1 - p[i];
ans[0][i] = tail * ans[0][i - 1];
for (long int h = 1; h <= i; h++) {
ans[h][i] = head * ans[h - 1][i - 1] + tail * ans[h][i - 1];
}
}
double answer = 0;
for (long int i = n / 2 + 1; i <= n; i++) {
answer = answer + ans[i][n];
}
cout << setprecision(9) << answer;
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define forr(i, a, b) for (int i = a; i < b; i++)
#define eb emplace_back
#define mp make_pair
typedef long long int lli;
typedef unsigned long long int ulli;
const int INF = INT_MAX;
const lli MOD = 10e8 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
std::cout.precision(30);
int n;
cin >> n;
vector<double> dp(n); // where dp[i]=(probablity of i heads)
dp[0] = 1;
forr(i, 0, n) {
double p;
cin >> p;
for (int k = i + 1; k >= 0; k--) /// we do this to avoid repition
{
dp[k] = dp[k - 1] * p +
dp[k] * (1 - p); // each coin either adds up or it does not
}
}
double sum = 0;
for (int i = n / 2 + 1; i < n + 1; i++)
sum += dp[i];
cout << sum << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define forr(i, a, b) for (int i = a; i < b; i++)
#define eb emplace_back
#define mp make_pair
typedef long long int lli;
typedef unsigned long long int ulli;
const int INF = INT_MAX;
const lli MOD = 10e8 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
std::cout.precision(30);
int n;
cin >> n;
vector<double> dp(n + 2); // where dp[i]=(probablity of i heads)
dp[0] = 1;
forr(i, 0, n) {
double p;
cin >> p;
for (int k = i + 1; k >= 0; k--) /// we do this to avoid repition
{
dp[k] = dp[k - 1] * p +
dp[k] * (1 - p); // each coin either adds up or it does not
}
}
double sum = 0;
for (int i = n / 2 + 1; i < n + 1; i++)
sum += dp[i];
cout << sum << endl;
return 0;
}
| replace | 15 | 16 | 15 | 16 | 0 | |
p03168 | C++ | Runtime Error | #include <iomanip>
#include <iostream>
const int MAXN = 300 + 5;
using namespace std;
int n;
long double dp[MAXN][MAXN], probability[MAXN];
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> probability[i];
dp[0][0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
dp[i + 1][j] += dp[i][j] * (1 - probability[i + 1]);
dp[i + 1][j + 1] += dp[i][j] * probability[i + 1];
}
}
long double ans = 0;
for (int j = n / 2 + 1; j <= n; j++)
ans += dp[n][j];
cout << setprecision(10) << fixed << ans;
return 0;
}
| #include <iomanip>
#include <iostream>
const int MAXN = 3000 + 5;
using namespace std;
int n;
long double dp[MAXN][MAXN], probability[MAXN];
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> probability[i];
dp[0][0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
dp[i + 1][j] += dp[i][j] * (1 - probability[i + 1]);
dp[i + 1][j + 1] += dp[i][j] * probability[i + 1];
}
}
long double ans = 0;
for (int j = n / 2 + 1; j <= n; j++)
ans += dp[n][j];
cout << setprecision(10) << fixed << ans;
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define FASTIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define ll double
#define vi vector<ll>
#define all(a) (a).begin(), (a).end()
#define rep(i, a, b) for (int i = a; i < b; i++)
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define pb push_back
#define endl "\n"
const int MAX = 30 + 3;
// const int mod=1e9+7;
int n;
vi v(MAX);
double dp[MAX][MAX];
/*
ll fun(int i,int k)
{
if(i==n && k<=n/2)
return 0;
if(i==n && k>n/2)
return 1;
if(dp[i][k]>=0)
return dp[i][k];
ll a=v[i]*fun(i+1,k+1);
ll b=(1-v[i])*fun(i+1,k);
dp[i][k]=a+b;
//cout<<a+b<<endl;;
return a+b;
}*/
ll fun() {
memset(dp, 0.0, sizeof(dp));
dp[0][0] = 1.0;
for (int i = 1; i <= n; i++) {
dp[i][0] = (1 - v[i - 1]) * dp[i - 1][0];
}
for (int i = 1; i <= n; i++) {
dp[i][i] = (v[i - 1]) * dp[i - 1][i - 1];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j < i; j++) {
dp[i][j] =
(dp[i - 1][j - 1] * v[i - 1]) + (dp[i - 1][j] * (1 - v[i - 1]));
}
}
/* rep(i,0,n+1)
{
rep(j,0,n+1)
{
cout<<dp[i][j]<<" ";
}
cout<<endl;
}*/
double ans = 0.0;
for (int i = (n / 2) + 1; i <= n; i++)
ans += dp[n][i];
return ans;
}
int main() {
FASTIO
cin >> n;
rep(i, 0, n) cin >> v[i];
double ans = fun();
cout << fixed << setprecision(12) << ans;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define FASTIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define ll double
#define vi vector<ll>
#define all(a) (a).begin(), (a).end()
#define rep(i, a, b) for (int i = a; i < b; i++)
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define pb push_back
#define endl "\n"
const int MAX = 3000 + 3;
// const int mod=1e9+7;
int n;
vi v(MAX);
double dp[MAX][MAX];
/*
ll fun(int i,int k)
{
if(i==n && k<=n/2)
return 0;
if(i==n && k>n/2)
return 1;
if(dp[i][k]>=0)
return dp[i][k];
ll a=v[i]*fun(i+1,k+1);
ll b=(1-v[i])*fun(i+1,k);
dp[i][k]=a+b;
//cout<<a+b<<endl;;
return a+b;
}*/
ll fun() {
memset(dp, 0.0, sizeof(dp));
dp[0][0] = 1.0;
for (int i = 1; i <= n; i++) {
dp[i][0] = (1 - v[i - 1]) * dp[i - 1][0];
}
for (int i = 1; i <= n; i++) {
dp[i][i] = (v[i - 1]) * dp[i - 1][i - 1];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j < i; j++) {
dp[i][j] =
(dp[i - 1][j - 1] * v[i - 1]) + (dp[i - 1][j] * (1 - v[i - 1]));
}
}
/* rep(i,0,n+1)
{
rep(j,0,n+1)
{
cout<<dp[i][j]<<" ";
}
cout<<endl;
}*/
double ans = 0.0;
for (int i = (n / 2) + 1; i <= n; i++)
ans += dp[n][i];
return ans;
}
int main() {
FASTIO
cin >> n;
rep(i, 0, n) cin >> v[i];
double ans = fun();
cout << fixed << setprecision(12) << ans;
return 0;
}
| replace | 13 | 14 | 13 | 14 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int, int>
#define pdd pair<double, double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repi(i, n) for (int i = 1; i <= n; ++i)
#define repn(i, n) for (int i = n - 1; i >= 0; --i)
#define repf(j, i, n) for (int j = i; j < n; ++j)
#define die(s) \
{ std::cout << s << nl; }
#define dier(s) \
{ \
std::cout << s; \
return 0; \
}
#define dbg(var) \
{ std::cout << #var << " = " << var << nl; }
#define vi vector<int>
typedef long long ll;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(11);
cout.setf(ios::fixed);
int n;
cin >> n;
vector<vector<double>> dp(n + 1, vector<double>(n));
dp[0][0] = 1.;
repi(i, n) {
double p;
cin >> p;
rep(j, i + 1) {
dp[i][j] = (j > 0 ? dp[i - 1][j - 1] * p : 0.) + dp[i - 1][j] * (1. - p);
}
}
double ans = 0.;
repf(i, 1 + n / 2, n + 1) ans += dp[n][i];
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int, int>
#define pdd pair<double, double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repi(i, n) for (int i = 1; i <= n; ++i)
#define repn(i, n) for (int i = n - 1; i >= 0; --i)
#define repf(j, i, n) for (int j = i; j < n; ++j)
#define die(s) \
{ std::cout << s << nl; }
#define dier(s) \
{ \
std::cout << s; \
return 0; \
}
#define dbg(var) \
{ std::cout << #var << " = " << var << nl; }
#define vi vector<int>
typedef long long ll;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(11);
cout.setf(ios::fixed);
int n;
cin >> n;
vector<vector<double>> dp(n + 1, vector<double>(n + 1));
dp[0][0] = 1.;
repi(i, n) {
double p;
cin >> p;
rep(j, i + 1) {
dp[i][j] = (j > 0 ? dp[i - 1][j - 1] * p : 0.) + dp[i - 1][j] * (1. - p);
}
}
double ans = 0.;
repf(i, 1 + n / 2, n + 1) ans += dp[n][i];
cout << ans << endl;
return 0;
} | replace | 41 | 42 | 41 | 42 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int tar = (n - 1) / 2 + 1;
vector<double> pn(tar + 1);
for (int i = 0; i < n; ++i)
cin >> pn[i];
vector<double> dp(n, 0);
dp[0] = 1;
for (int i = 0; i < n; ++i)
for (int j = min(i + 1, tar); j >= 0; --j) {
if (j == tar)
dp[j] = dp[j] + dp[j - 1] * pn[i];
else if (j != 0)
dp[j] = dp[j] * (1 - pn[i]) + dp[j - 1] * pn[i];
else
dp[j] = dp[j] * (1 - pn[i]);
}
printf("%.10f\n", dp[tar]);
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int tar = (n - 1) / 2 + 1;
vector<double> pn(3000);
for (int i = 0; i < n; ++i)
cin >> pn[i];
vector<double> dp(n, 0);
dp[0] = 1;
for (int i = 0; i < n; ++i)
for (int j = min(i + 1, tar); j >= 0; --j) {
if (j == tar)
dp[j] = dp[j] + dp[j - 1] * pn[i];
else if (j != 0)
dp[j] = dp[j] * (1 - pn[i]) + dp[j - 1] * pn[i];
else
dp[j] = dp[j] * (1 - pn[i]);
}
printf("%.10f\n", dp[tar]);
} | replace | 7 | 8 | 7 | 8 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, j, k) for (int i = (int)j; i <= (int)k; i++)
#define debug(x) cerr << #x << ":" << x << endl
const int maxn = (int)1e6 + 5;
double p[maxn], dp[1004][1004], ans;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
rep(i, 1, n) cin >> p[i];
dp[0][0] = 1;
rep(i, 1, n) rep(j, 0, i) {
dp[i][j] =
dp[i - 1][j] * (1 - p[i]) + (j > 0 ? dp[i - 1][j - 1] * p[i] : 0);
// debug(i),debug(dp[i][j]);
}
rep(j, 0, n) {
if (j > n - j)
ans += dp[n][j];
}
// cout<<ans<<endl;
printf("%.20lf", ans);
}
/*
3
0.30 0.60 0.80
head>tail 的概率
dp[i][#head] dp[i][j]=dp[i-1][j] dp[i-1][j-1]
O(1)计算
最后求和
*/ | #include <bits/stdc++.h>
using namespace std;
#define rep(i, j, k) for (int i = (int)j; i <= (int)k; i++)
#define debug(x) cerr << #x << ":" << x << endl
const int maxn = (int)1e6 + 5;
double p[maxn], dp[3004][3004], ans;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
rep(i, 1, n) cin >> p[i];
dp[0][0] = 1;
rep(i, 1, n) rep(j, 0, i) {
dp[i][j] =
dp[i - 1][j] * (1 - p[i]) + (j > 0 ? dp[i - 1][j - 1] * p[i] : 0);
// debug(i),debug(dp[i][j]);
}
rep(j, 0, n) {
if (j > n - j)
ans += dp[n][j];
}
// cout<<ans<<endl;
printf("%.20lf", ans);
}
/*
3
0.30 0.60 0.80
head>tail 的概率
dp[i][#head] dp[i][j]=dp[i-1][j] dp[i-1][j-1]
O(1)计算
最后求和
*/ | replace | 5 | 6 | 5 | 6 | 0 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// #define PRAGMA 448
#ifdef PRAGMA
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#ifdef LUCARIO
#define deb(...) fprintf(stderr, __VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
typedef int intt;
typedef pair<long long, long long> pll;
typedef pair<int, int> pii;
#define FIN \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define ll long long
#define ld long double
#define int long long
#define pb push_back
#define bs binary_search
#define up upper_bound
#define fs first
#define sd second
#define mp make_pair
#define endl "\n"
#define fore(i, a, b) for (ll i = a; i < b; i++)
#define rfore(i, a, b) for (ll i = a - 1; i >= b; i--)
#define forev(a, b) fore(i, 0, b) cout << a[i] << " ";
#define ing(g, u, v) \
g[u].pb(v); \
g[v].pb(u);
#define ingp(g, u, v, c) (g[u].pb({v, c}); g[v].pb({u, c});)
#define mm(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(n) ((ll)(n).size())
#define sfind(s, t) (s.find(t) != string::npos)
#define infll (ll)1e15
#define infi (int)(1e9 + 1)
#define PI 3.14159265359
#define mod (ll)(1e9 + 7)
#define eps 1e-6
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
int n, m;
ld a[1001];
ld dp[3001][3001];
double res;
ld solve(int i, int j) {
if (i == n)
return (j > n / 2);
ld &r = dp[i][j];
if (r >= 0)
return r;
r = 0;
r += solve(i + 1, j + 1) * a[i] + solve(i + 1, j) * (1 - a[i]);
return r;
}
int32_t main(int32_t argc, char const *argv[]) {
FIN;
fore(i, 0, 3001) {
fore(j, 0, 3001) { dp[i][j] = -1; }
}
cin >> n;
fore(i, 0, n) cin >> a[i];
cout << setprecision(16) << solve(0, 0) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
// #define PRAGMA 448
#ifdef PRAGMA
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#ifdef LUCARIO
#define deb(...) fprintf(stderr, __VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
typedef int intt;
typedef pair<long long, long long> pll;
typedef pair<int, int> pii;
#define FIN \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define ll long long
#define ld long double
#define int long long
#define pb push_back
#define bs binary_search
#define up upper_bound
#define fs first
#define sd second
#define mp make_pair
#define endl "\n"
#define fore(i, a, b) for (ll i = a; i < b; i++)
#define rfore(i, a, b) for (ll i = a - 1; i >= b; i--)
#define forev(a, b) fore(i, 0, b) cout << a[i] << " ";
#define ing(g, u, v) \
g[u].pb(v); \
g[v].pb(u);
#define ingp(g, u, v, c) (g[u].pb({v, c}); g[v].pb({u, c});)
#define mm(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(n) ((ll)(n).size())
#define sfind(s, t) (s.find(t) != string::npos)
#define infll (ll)1e15
#define infi (int)(1e9 + 1)
#define PI 3.14159265359
#define mod (ll)(1e9 + 7)
#define eps 1e-6
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
int n, m;
ld a[3001];
ld dp[3001][3001];
double res;
ld solve(int i, int j) {
if (i == n)
return (j > n / 2);
ld &r = dp[i][j];
if (r >= 0)
return r;
r = 0;
r += solve(i + 1, j + 1) * a[i] + solve(i + 1, j) * (1 - a[i]);
return r;
}
int32_t main(int32_t argc, char const *argv[]) {
FIN;
fore(i, 0, 3001) {
fore(j, 0, 3001) { dp[i][j] = -1; }
}
cin >> n;
fore(i, 0, n) cin >> a[i];
cout << setprecision(16) << solve(0, 0) << endl;
return 0;
}
| replace | 60 | 61 | 60 | 61 | -11 | |
p03168 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define foru(i, a, b) for (ll i = a; i < b; i++)
#define ford(i, a, b) for (ll i = a; i >= b; i--)
#define ain(a, n) \
for (ll i = 0; i < n; i++) \
cin >> a[i]
#define aout(a, n) \
for (ll i = 0; i < n; i++) \
cout << a[i] << " "
#define M 1000000007
#define mp make_pair
#define mt make_tuple
#define cend cout << "\n"
#define all(x) x.begin(), x.end()
#define aout2(a, n, m) \
for (ll i = 0; i < n; i++) { \
for (ll j = 0; j < m; j++) { \
cout << a[i][j] << " "; \
} \
cout << endl; \
}
#define ain2(a, n, m) \
for (ll i = 0; i < n; i++) { \
for (ll j = 0; j < m; j++) { \
cin >> a[i][j]; \
} \
}
#define ff first
#define ss second
#define mset(a, b) memset(a, b, sizeof(a))
#ifndef ONLINE_JUDGE
#define dbg(a) \
cerr << #a << ": "; \
_print(a); \
cerr << endl;
#else
#define dbg(a) // No more TLEs
#endif
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vch;
typedef vector<string> vs;
typedef set<ll> sll;
typedef multiset<ll> msll;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
void _print(ll t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(ldb t) { cerr << t; }
template <class T, class V> void _print(pair<T, V> p);
template <class T> void _print(vector<T> v);
template <class T> void _print(set<T> v);
template <class T, class V> void _print(map<T, V> v);
template <class T, class V> void _print(pair<T, V> p) {
cerr << "{";
_print(p.ff);
cerr << ",";
_print(p.ss);
cerr << "}";
}
template <class T> void _print(vector<T> v) {
cerr << "[ ";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T> void _print(set<T> v) {
cerr << "[ ";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T, class V> void _print(map<T, V> v) {
cerr << "[ ";
for (auto i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
/*----------------------------- # --- MATH ALGORITHMS --- #
* -----------------------------*/
template <class T> T gcd(T a, T b) {
while (a != 0) {
T temp = a;
a = b % a;
b = temp;
}
return b;
}
template <class T> T egcd(T a, T b, T &x, T &y) {
T gcd, xt, yt;
if (a == 0) {
gcd = b;
x = 0, y = 1;
} else {
gcd = egcd(b % a, a, xt, yt);
x = yt - (b / a) * xt;
y = xt;
}
return gcd;
}
template <class T> T expo(T base, T exp, T mod) {
T res = 1;
base = base % mod;
while (exp > 0) {
if (exp & 1)
res = (res * base) % mod;
exp = exp >> 1;
base = (base * base) % mod;
}
return res;
}
template <class T> T modinv(T a, T mod) {
T x, y;
egcd<T>(a, mod, x, y);
while (x < 0)
x += mod;
while (x >= mod)
x -= mod;
return x;
}
template <class T> T modinvfermat(T a, T mod) {
return expo<T>(a, mod - 2, mod);
}
template <class T> bool rev(T a, T b) { return a > b; }
template <class T> ll maxpower(T a, T b) {
ll ans = 0;
while (a > 0 && a % b == 0) {
ans++;
a /= b;
}
return ans;
}
template <class T> T mceil(T a, T b) {
if (a % b == 0)
return a / b;
else
return a / b + 1;
}
template <class T> T lcm(T a, T b) { return (a * b) / gcd<T>(a, b); }
/*----------------------------- # --- MAIN CODE --- #
* -----------------------------*/
int main() {
fastio;
#ifndef ONLINE_JUDGE
freopen("testcase.txt", "r", stdin);
freopen("error.txt", "w", stderr);
freopen("output.txt", "w", stdout);
#endif
ll n;
cin >> n;
vector<vector<ldb>> dp(n + 1, vector<ldb>(n + 1, 0));
vector<ldb> a(n);
ain(a, n);
dp[1][0] = 1 - a[0];
dp[1][1] = a[0];
ldb prod = 1;
foru(i, 0, n) {
prod *= (1 - a[i]);
dp[i + 1][0] = prod;
}
foru(i, 2, n + 1) {
foru(j, 1, n + 1) {
dp[i][j] = dp[i - 1][j] * (1 - a[i - 1]) + dp[i - 1][j - 1] * a[i - 1];
}
}
ldb ans = 0;
// dbg(dp);
foru(i, n / 2 + 1, n + 1) { ans += dp[n][i]; }
cout << setprecision(10);
cout << ans;
}
| #include <algorithm>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define foru(i, a, b) for (ll i = a; i < b; i++)
#define ford(i, a, b) for (ll i = a; i >= b; i--)
#define ain(a, n) \
for (ll i = 0; i < n; i++) \
cin >> a[i]
#define aout(a, n) \
for (ll i = 0; i < n; i++) \
cout << a[i] << " "
#define M 1000000007
#define mp make_pair
#define mt make_tuple
#define cend cout << "\n"
#define all(x) x.begin(), x.end()
#define aout2(a, n, m) \
for (ll i = 0; i < n; i++) { \
for (ll j = 0; j < m; j++) { \
cout << a[i][j] << " "; \
} \
cout << endl; \
}
#define ain2(a, n, m) \
for (ll i = 0; i < n; i++) { \
for (ll j = 0; j < m; j++) { \
cin >> a[i][j]; \
} \
}
#define ff first
#define ss second
#define mset(a, b) memset(a, b, sizeof(a))
#ifndef ONLINE_JUDGE
#define dbg(a) \
cerr << #a << ": "; \
_print(a); \
cerr << endl;
#else
#define dbg(a) // No more TLEs
#endif
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vch;
typedef vector<string> vs;
typedef set<ll> sll;
typedef multiset<ll> msll;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
void _print(ll t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(ldb t) { cerr << t; }
template <class T, class V> void _print(pair<T, V> p);
template <class T> void _print(vector<T> v);
template <class T> void _print(set<T> v);
template <class T, class V> void _print(map<T, V> v);
template <class T, class V> void _print(pair<T, V> p) {
cerr << "{";
_print(p.ff);
cerr << ",";
_print(p.ss);
cerr << "}";
}
template <class T> void _print(vector<T> v) {
cerr << "[ ";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T> void _print(set<T> v) {
cerr << "[ ";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T, class V> void _print(map<T, V> v) {
cerr << "[ ";
for (auto i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
/*----------------------------- # --- MATH ALGORITHMS --- #
* -----------------------------*/
template <class T> T gcd(T a, T b) {
while (a != 0) {
T temp = a;
a = b % a;
b = temp;
}
return b;
}
template <class T> T egcd(T a, T b, T &x, T &y) {
T gcd, xt, yt;
if (a == 0) {
gcd = b;
x = 0, y = 1;
} else {
gcd = egcd(b % a, a, xt, yt);
x = yt - (b / a) * xt;
y = xt;
}
return gcd;
}
template <class T> T expo(T base, T exp, T mod) {
T res = 1;
base = base % mod;
while (exp > 0) {
if (exp & 1)
res = (res * base) % mod;
exp = exp >> 1;
base = (base * base) % mod;
}
return res;
}
template <class T> T modinv(T a, T mod) {
T x, y;
egcd<T>(a, mod, x, y);
while (x < 0)
x += mod;
while (x >= mod)
x -= mod;
return x;
}
template <class T> T modinvfermat(T a, T mod) {
return expo<T>(a, mod - 2, mod);
}
template <class T> bool rev(T a, T b) { return a > b; }
template <class T> ll maxpower(T a, T b) {
ll ans = 0;
while (a > 0 && a % b == 0) {
ans++;
a /= b;
}
return ans;
}
template <class T> T mceil(T a, T b) {
if (a % b == 0)
return a / b;
else
return a / b + 1;
}
template <class T> T lcm(T a, T b) { return (a * b) / gcd<T>(a, b); }
/*----------------------------- # --- MAIN CODE --- #
* -----------------------------*/
int main() {
fastio;
ll n;
cin >> n;
vector<vector<ldb>> dp(n + 1, vector<ldb>(n + 1, 0));
vector<ldb> a(n);
ain(a, n);
dp[1][0] = 1 - a[0];
dp[1][1] = a[0];
ldb prod = 1;
foru(i, 0, n) {
prod *= (1 - a[i]);
dp[i + 1][0] = prod;
}
foru(i, 2, n + 1) {
foru(j, 1, n + 1) {
dp[i][j] = dp[i - 1][j] * (1 - a[i - 1]) + dp[i - 1][j - 1] * a[i - 1];
}
}
ldb ans = 0;
// dbg(dp);
foru(i, n / 2 + 1, n + 1) { ans += dp[n][i]; }
cout << setprecision(10);
cout << ans;
}
| replace | 181 | 186 | 181 | 182 | -11 | |
p03168 | C++ | Runtime Error | #include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<double> dp(n);
dp[0] = 1;
for (int i = 0; i < n; ++i) {
double p;
cin >> p;
for (int j = i + 1; j >= 0; --j) {
dp[j] = ((j == 0) ? 0 : dp[j - 1] * p) + dp[j] * (1 - p);
}
}
double ans = 0.0;
for (int i = 0; i <= n; ++i) {
if (i > n - i)
ans += dp[i];
}
cout << fixed << setprecision(10);
cout << ans << endl;
} | #include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<double> dp(n + 1);
dp[0] = 1;
for (int i = 0; i < n; ++i) {
double p;
cin >> p;
for (int j = i + 1; j >= 0; --j) {
dp[j] = ((j == 0) ? 0 : dp[j - 1] * p) + dp[j] * (1 - p);
}
}
double ans = 0.0;
for (int i = 0; i <= n; ++i) {
if (i > n - i)
ans += dp[i];
}
cout << fixed << setprecision(10);
cout << ans << endl;
} | replace | 13 | 14 | 13 | 14 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.