Problem p03168 (C++)

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


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