Problem p03168 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int>>
#define FASTIO                                                                 \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define index INDEX
#ifndef ONLINE_JUDGE
#define print(x) PRINT(x, #x)
template <typename T> void PRINT(T VARIABLE, const string &NAME) {
  cerr << NAME << " = " << fixed << VARIABLE << "\n";
}
#else
#define print(x) 0
#endif
int generate_random() {
  const int MAX_RANDOM = (int)1e6;
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  return uniform_int_distribution<int>(0, MAX_RANDOM)(rng);
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll INFLL = 2 * (ll)1e18 + 100;
#define int ll
#ifdef int
const int INFINT = INFLL;
#else
const int INFINT = 2 * (int)1e9 + 100;
#endif
const double PI = atan(1) * 4;
const double EPS = 1e-6;
const int SEED = (int)1e3 + 7;
const int MOD = (int)1e9 + 7;
const int NMAX = (int)1e3 + 5;

double p[NMAX];
double dp[NMAX][NMAX];

int32_t main() {
#ifndef ONLINE_JUDGE
  double START_PROGRAM = clock();
#endif
  srand(time(NULL));
  cout << setprecision(20) << fixed;
  FASTIO;
  int n;
  cin >> n;
  for1(i, n) cin >> p[i];

  dp[1][1] = p[1];
  dp[1][0] = 1 - p[1];
  for (int i = 2; i <= n; i++) {
    dp[i][0] = dp[i - 1][0] * (1 - p[i]);
    for1(j, i) dp[i][j] = dp[i - 1][j] * (1 - p[i]) + dp[i - 1][j - 1] * p[i];
  }

  double sol = 0;
  for (int j = n / 2 + 1; j <= n; j++)
    sol += dp[n][j];
  cout << sol;

#ifndef ONLINE_JUDGE
  double END_PROGRAM = clock();
  double ELAPSED_TIME = (END_PROGRAM - START_PROGRAM) / CLOCKS_PER_SEC;
  cerr << "\n\nElapsed Time: " << ELAPSED_TIME * 1000 << "\n";
#endif
  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int>>
#define FASTIO                                                                 \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define index INDEX
#ifndef ONLINE_JUDGE
#define print(x) PRINT(x, #x)
template <typename T> void PRINT(T VARIABLE, const string &NAME) {
  cerr << NAME << " = " << fixed << VARIABLE << "\n";
}
#else
#define print(x) 0
#endif
int generate_random() {
  const int MAX_RANDOM = (int)1e6;
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  return uniform_int_distribution<int>(0, MAX_RANDOM)(rng);
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll INFLL = 2 * (ll)1e18 + 100;
#define int ll
#ifdef int
const int INFINT = INFLL;
#else
const int INFINT = 2 * (int)1e9 + 100;
#endif
const double PI = atan(1) * 4;
const double EPS = 1e-6;
const int SEED = (int)1e3 + 7;
const int MOD = (int)1e9 + 7;
const int NMAX = (int)3 * 1e3 + 5;

double p[NMAX];
double dp[NMAX][NMAX];

int32_t main() {
#ifndef ONLINE_JUDGE
  double START_PROGRAM = clock();
#endif
  srand(time(NULL));
  cout << setprecision(20) << fixed;
  FASTIO;
  int n;
  cin >> n;
  for1(i, n) cin >> p[i];

  dp[1][1] = p[1];
  dp[1][0] = 1 - p[1];
  for (int i = 2; i <= n; i++) {
    dp[i][0] = dp[i - 1][0] * (1 - p[i]);
    for1(j, i) dp[i][j] = dp[i - 1][j] * (1 - p[i]) + dp[i - 1][j - 1] * p[i];
  }

  double sol = 0;
  for (int j = n / 2 + 1; j <= n; j++)
    sol += dp[n][j];
  cout << sol;

#ifndef ONLINE_JUDGE
  double END_PROGRAM = clock();
  double ELAPSED_TIME = (END_PROGRAM - START_PROGRAM) / CLOCKS_PER_SEC;
  cerr << "\n\nElapsed Time: " << ELAPSED_TIME * 1000 << "\n";
#endif
  return 0;
}