Problem p03168 (C++)

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

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