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

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

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

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


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

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


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

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


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

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


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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

Fixed submission:

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

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

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

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


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

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

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

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

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

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

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

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


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

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


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

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


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

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


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

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


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

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


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

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

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

Buggy submission (status: 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)计算
最后求和
 */

Fixed submission:
#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)计算
最后求和
 */
Problem p03168 (C++)

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

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