prithivMLmods/Coder-Stat huggingface dataset:
Problem p03168 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
double dp[3001][3001];
double helper(int numheads, int i, vector<double> &prob, int n) {
  if (dp[i][numheads] > -1) {
    return dp[i][numheads];
  }
  if (i >= n) {
    if (numheads <= n / 2) {
      return 0;
    } else
      return 1;
  } else {
    return prob[i] * helper(numheads + 1, i + 1, prob, n) +
           helper(numheads, i + 1, prob, n) * (1 - prob[i]);
  }
}
int main() {
  int n;
  cin >> n;
  vector<double> prob(n);
  for (int i = 0; i < n; i++) {
    cin >> prob[i];
  }
  double ans = 0;
  for (int i = 0; i < 3001; i++) {
    for (int j = 0; j < 3001; j++) {
      dp[i][j] = -1;
    }
  }
  cout << setprecision(15);
  cout << helper(0, 0, prob, n);
}


Fixed submission:
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
double dp[3001][3001];
double helper(int numheads, int i, vector<double> &prob, int n) {
  if (dp[i][numheads] > -1) {
    return dp[i][numheads];
  }
  if (i >= n) {
    if (numheads <= n / 2) {
      return 0;
    } else
      return 1;
  } else {
    dp[i][numheads] = prob[i] * helper(numheads + 1, i + 1, prob, n) +
                      helper(numheads, i + 1, prob, n) * (1 - prob[i]);
    return dp[i][numheads];
  }
}
int main() {
  int n;
  cin >> n;
  vector<double> prob(n);
  for (int i = 0; i < n; i++) {
    cin >> prob[i];
  }
  double ans = 0;
  for (int i = 0; i < 3001; i++) {
    for (int j = 0; j < 3001; j++) {
      dp[i][j] = -1;
    }
  }
  cout << setprecision(15);
  cout << helper(0, 0, prob, n);
}
Problem p03168 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define nt _int128
#define mod 1000000007
double arr[3005], dp[3005][3005];
ll n;
double func(ll i, ll k) {
  if (i == n + 1) {
    if (k == 0)
      return 1.0;
    else
      return 0.0;
  } else if (dp[i][k] != -1.0) {
    return dp[i][k];
  }

  double x = 0;
  if (k > 0)
    x += arr[i] * func(i + 1, k - 1);
  x += (1 - arr[i]) * func(i + 1, k);
  return dp[i][k] = x;
}
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);
  ll t;
  // cin >> t;
  t = 1;
  while (t--) {
    cin >> n;
    for (ll i = 1; i <= n; i++)
      cin >> arr[i];
    double x = 0;
    for (ll i = 1; i <= 3000; i++) {
      for (ll j = 0; j <= 3000; j++)
        dp[i][j] = -1.0;
    }
    for (ll i = n / 2 + 1; i <= n; i++) {
      x += func(1, i);
    }
    // for(ll i=1;i<=n;i++)
    // {
    //     for(ll j=0;j<=2;j++)
    //         cout<<dp[i][j]<<" ";
    //     cout<<endl;
    // }
    cout << fixed << setprecision(10) << x;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define nt _int128
#define mod 1000000007
double arr[3005], dp[3005][3005];
ll n;
double func(ll i, ll k) {
  if (i == n + 1) {
    if (k == 0)
      return 1.0;
    else
      return 0.0;
  } else if (dp[i][k] != -1.0) {
    return dp[i][k];
  }

  double x = 0;
  if (k > 0)
    x += arr[i] * func(i + 1, k - 1);
  x += (1 - arr[i]) * func(i + 1, k);
  return dp[i][k] = x;
}
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);
  ll t;
  // cin >> t;
  t = 1;
  while (t--) {
    cin >> n;
    for (ll i = 1; i <= n; i++)
      cin >> arr[i];
    double x = 0;
    for (ll i = 1; i <= 3000; i++) {
      for (ll j = 0; j <= 3000; j++)
        dp[i][j] = -1.0;
    }
    for (ll i = n / 2 + 1; i <= n; i++) {
      x += func(1, i);
    }
    // for(ll i=1;i<=n;i++)
    // {
    //     for(ll j=0;j<=2;j++)
    //         cout<<dp[i][j]<<" ";
    //     cout<<endl;
    // }
    cout << fixed << setprecision(10) << x;
  }
  return 0;
}
Problem p03168 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int main() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  cout.precision(10);
  int n;
  cin >> n;
  vector<vector<double>> dp(n + 1, vector<double>(n + 1));
  vector<double> v(n + 1);
  for (int i = 1; i <= n; i++)
    cin >> v[i];
  dp[0][0] = 1.0;
  for (int i = 1; i <= n; i++) {
    dp[i][0] = dp[i - 1][0] * (1 - v[i]);
    for (int j = 1; j <= i; j++) {
      dp[i][j] = dp[i - 1][j - 1] * v[i] + dp[i - 1][j] * (1 - v[i]);
    }
  }
  double ans = 0.0;
  for (int i = (n + 1) / 2; i <= n; i++)
    ans = ans + dp[n][i];
  cout << ans << '\n';
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main() {
  //	freopen("input.txt","r",stdin);
  //	freopen("output.txt","w",stdout);
  cout.precision(10);
  int n;
  cin >> n;
  vector<vector<double>> dp(n + 1, vector<double>(n + 1));
  vector<double> v(n + 1);
  for (int i = 1; i <= n; i++)
    cin >> v[i];
  dp[0][0] = 1.0;
  for (int i = 1; i <= n; i++) {
    dp[i][0] = dp[i - 1][0] * (1 - v[i]);
    for (int j = 1; j <= i; j++) {
      dp[i][j] = dp[i - 1][j - 1] * v[i] + dp[i - 1][j] * (1 - v[i]);
    }
  }
  double ans = 0.0;
  for (int i = (n + 1) / 2; i <= n; i++)
    ans = ans + dp[n][i];
  cout << ans << '\n';
  return 0;
}
Problem p03168 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i, a, b) for (int i = (a); i < (b); i++)
#define frr(i, a, b) for (int i = (a - 1); i >= (b); i--)
#define vi vector<int>
#define de deque<int>
#define del deque<ll>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define mp map<ll, ll>
#define rev(a) reverse(a.begin(), a.end())
#define srt(a) sort(a.begin(), a.end())
#define rsrt(a) sort(a.begin(), a.end(), greater<int>())
#define ln(a) a.length()
#define sz(a) a.size()
ll M = 1e9 + 7;
int n;
double a[3001];
double dp[3001][3001];
int ready[3001][3001];
double solve(int ind, int num) {
  if (ready[ind][num])
    return dp[ind][num];
  if (ind == 0) {
    return 0.0;
  }
  if (num == 0)
    return (1 - a[ind]) * solve(ind - 1, num);

  ready[ind][num] = 1;
  return dp[ind][num] = a[ind] * solve(ind - 1, num - 1) +
                        (1.0 - a[ind]) * solve(ind - 1, num);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  cin >> n;
  fr(i, 1, n + 1) cin >> a[i];
  memset(ready, 0, sizeof ready);
  fr(i, 0, 3001) fr(j, 0, 3001) dp[i][j] = 0.0;
  ready[0][0] = 1;
  dp[0][0] = 1.0;

  double ans = 0;
  fr(i, 0, n + 1) {
    if (i > n / 2)
      ans += solve(n, i);
  }

  cout << setprecision(12) << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i, a, b) for (int i = (a); i < (b); i++)
#define frr(i, a, b) for (int i = (a - 1); i >= (b); i--)
#define vi vector<int>
#define de deque<int>
#define del deque<ll>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define mp map<ll, ll>
#define rev(a) reverse(a.begin(), a.end())
#define srt(a) sort(a.begin(), a.end())
#define rsrt(a) sort(a.begin(), a.end(), greater<int>())
#define ln(a) a.length()
#define sz(a) a.size()
ll M = 1e9 + 7;
int n;
double a[3001];
double dp[3001][3001];
int ready[3001][3001];
double solve(int ind, int num) {
  if (ready[ind][num])
    return dp[ind][num];
  if (ind == 0) {
    return 0.0;
  }
  if (num == 0)
    return (1 - a[ind]) * solve(ind - 1, num);

  ready[ind][num] = 1;
  return dp[ind][num] = a[ind] * solve(ind - 1, num - 1) +
                        (1.0 - a[ind]) * solve(ind - 1, num);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  // #endif
  cin >> n;
  fr(i, 1, n + 1) cin >> a[i];
  memset(ready, 0, sizeof ready);
  fr(i, 0, 3001) fr(j, 0, 3001) dp[i][j] = 0.0;
  ready[0][0] = 1;
  dp[0][0] = 1.0;

  double ans = 0;
  fr(i, 0, n + 1) {
    if (i > n / 2)
      ans += solve(n, i);
  }

  cout << setprecision(12) << ans << endl;
}
Problem p03168 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cstring>
#include <inttypes.h>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <utility>
#include <vector>

using namespace std;

const int cap = 3000;
int N;
double p;
double dp[cap];

int main() {
  scanf("%d", &N);
  fill(dp, dp + N + 1, 0);
  dp[0] = 1;
  for (int i = 1; i <= N; ++i) {
    scanf(" %lf", &p);
    for (int j = i; j > 0; --j) {
      dp[j] = dp[j] * (1 - p) + dp[j - 1] * p;
    }
    dp[0] *= 1 - p;
  }
  double ans = accumulate(dp + N / 2 + 1, dp + N * N + 1, (double)0);
  printf("%.10lf\n", ans);
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cstring>
#include <inttypes.h>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <utility>
#include <vector>

using namespace std;

const int cap = 3000;
int N;
double p;
double dp[cap];

int main() {
  scanf("%d", &N);
  fill(dp, dp + N + 1, 0);
  dp[0] = 1;
  for (int i = 1; i <= N; ++i) {
    scanf(" %lf", &p);
    for (int j = i; j > 0; --j) {
      dp[j] = dp[j] * (1 - p) + dp[j - 1] * p;
    }
    dp[0] *= 1 - p;
  }
  double ans = accumulate(dp + N / 2 + 1, dp + N + 1, (double)0);
  printf("%.10lf\n", ans);
}
Problem p03168 (C++)

Buggy submission (status: Runtime Error):
#include <iomanip>
#include <iostream>
#include <vector>
#define prDouble(x) cout << fixed << setprecision(10) << x
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<double> prob(n + 1);
  for (int i = 1; i <= n; ++i)
    cin >> prob[i];
  int x = ((n + 1) / 2) + 1;
  double dp[n][x];
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j < x; ++j) {
      if (i == 0 && j == 0)
        dp[i][j] = 1;
      else if (i == 0)
        dp[i][j] = 0;
      else if (j == 0)
        dp[i][j] = 1;
      else
        dp[i][j] = prob[i] * dp[i - 1][j - 1] + (1 - prob[i]) * dp[i - 1][j];
    }
  }
  prDouble(dp[n][x - 1]);
  cout << "\n";
  return 0;
}

Fixed submission:
#include <iomanip>
#include <iostream>
#include <vector>
#define prDouble(x) cout << fixed << setprecision(10) << x
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<double> prob(n + 1);
  for (int i = 1; i <= n; ++i)
    cin >> prob[i];
  int x = ((n + 1) / 2) + 1;
  double dp[n + 1][x];
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j < x; ++j) {
      if (i == 0 && j == 0)
        dp[i][j] = 1;
      else if (i == 0)
        dp[i][j] = 0;
      else if (j == 0)
        dp[i][j] = 1;
      else
        dp[i][j] = prob[i] * dp[i - 1][j - 1] + (1 - prob[i]) * dp[i - 1][j];
    }
  }
  prDouble(dp[n][x - 1]);
  cout << "\n";
  return 0;
}
Problem p03168 (C++)

Buggy submission (status: Runtime Error):

#include "bits/stdc++.h"
using namespace std;

#define cool                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);

#define int long long int
#define pb push_back
#define fe first
#define lb lower_bound
#define ub upper_bound
#define pii pair<pair<int, int>, pair<int, int>>
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define bs binary_search
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rep1(i, a, b) for (int i = a; i <= b; i++)
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)x.size()
#define PI 3.14159265358979323846

const int N = 1e3 + 5;

int mod = 1e9 + 7;
int dx[4] = {0, 0, +1, -1};
int dy[4] = {+1, -1, 0, 0};

long double a[N][N], p[N], sum;

void solve() {
  int n;
  cin >> n;

  rep(i, 0, n) cin >> p[i];

  a[0][0] = 1;

  rep(i, 0, n) {
    rep(j, 0, i + 1) {
      a[i + 1][j + 1] += a[i][j] * p[i];
      a[i + 1][j] += a[i][j] * (1 - p[i]);
    }
  }

  int bg = (n + 1) / 2;

  rep(i, bg, n + 1) sum += a[n][i];

  cout << fixed << setprecision(10) << sum << endl;

  // cout<<sum<<endl;
}

int32_t main() {
  cool;
  int t = 1;
  // cin>>t;
  while (t--)
    solve();

  return 0;
}


Fixed submission:

#include "bits/stdc++.h"
using namespace std;

#define cool                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);

#define int long long int
#define pb push_back
#define fe first
#define lb lower_bound
#define ub upper_bound
#define pii pair<pair<int, int>, pair<int, int>>
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define bs binary_search
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rep1(i, a, b) for (int i = a; i <= b; i++)
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)x.size()
#define PI 3.14159265358979323846

const int N = 3e3 + 5;

int mod = 1e9 + 7;
int dx[4] = {0, 0, +1, -1};
int dy[4] = {+1, -1, 0, 0};

long double a[N][N], p[N], sum;

void solve() {
  int n;
  cin >> n;

  rep(i, 0, n) cin >> p[i];

  a[0][0] = 1;

  rep(i, 0, n) {
    rep(j, 0, i + 1) {
      a[i + 1][j + 1] += a[i][j] * p[i];
      a[i + 1][j] += a[i][j] * (1 - p[i]);
    }
  }

  int bg = (n + 1) / 2;

  rep(i, bg, n + 1) sum += a[n][i];

  cout << fixed << setprecision(10) << sum << endl;

  // cout<<sum<<endl;
}

int32_t main() {
  cool;
  int t = 1;
  // cin>>t;
  while (t--)
    solve();

  return 0;
}
Problem p03168 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
vector<vector<double>> dp;
double solve(double 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] * solve(a, i - 1, x - 1)) +
                    ((1 - a[i]) * solve(a, i - 1, x));
}
int main() {
  int n;
  cin >> n;
  double a[n + 1];
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  dp.resize(n, vector<double>(n, -1));
  cout << fixed << setprecision(10) << solve(a, n, (n + 1) / 2);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
vector<vector<double>> dp;
double solve(double 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] * solve(a, i - 1, x - 1)) +
                    ((1 - a[i]) * solve(a, i - 1, x));
}
int main() {
  int n;
  cin >> n;
  double a[n + 1];
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  dp.resize(n + 1, vector<double>(n + 1, -1));
  cout << fixed << setprecision(10) << solve(a, n, (n + 1) / 2);
  return 0;
}
Problem p03168 (C++)

Buggy submission (status: 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;
}

Fixed submission:
#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;
}
Problem p03168 (C++)

Buggy submission (status: 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;
}

Fixed submission:
// 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;
}
Problem p03168 (C++)

Buggy submission (status: 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;
}

Fixed submission:
#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;
}
Problem p03168 (C++)

Buggy submission (status: 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;
}


Fixed submission:
#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;
}
Problem p03168 (C++)

Buggy submission (status: 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;
}


Fixed submission:
#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;
}
Problem p03168 (C++)

Buggy submission (status: 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;
}


Fixed submission:
#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;
}
Problem p03168 (C++)

Buggy submission (status: 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;
}


Fixed submission:
#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;
}
Problem p03168 (C++)

Buggy submission (status: 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;
  }
}

Fixed submission:
#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;
  }
}
Problem p03168 (C++)

Buggy submission (status: 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;
}


Fixed submission:
#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;
}
Problem p03168 (C++)

Buggy submission (status: 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
*/

Fixed submission:
#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
*/
Problem p03168 (C++)

Buggy submission (status: 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;
}


Fixed submission:
#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;
}
Problem p03168 (C++)

Buggy submission (status: 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;
}


Fixed submission:
#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;
}
Problem p03168 (C++)

Buggy submission (status: 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;
}

Fixed submission:
#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;
}
Problem p03168 (C++)

Buggy submission (status: 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);
}


Fixed submission:
#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);
}
Problem p03168 (C++)

Buggy submission (status: 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;
}


Fixed submission:
#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;
}
Problem p03168 (C++)

Buggy submission (status: 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;
}

Fixed submission:
#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;
}
Problem p03168 (C++)

Buggy submission (status: 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;
}

Fixed submission:
#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;
}