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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define printWithPrecision(x) cout << fixed << setprecision(10) << x << endl;
double dp[3001][3001];

double solve(vector<double> v, ll i, ll 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] = (v[i] * solve(v, i - 1, x - 1)) +
                    (((double)1 - v[i]) * solve(v, i - 1, x));
}

void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main() {
  fast();
  ll n;
  cin >> n;
  memset(dp, -1, sizeof dp);

  vector<double> v(n + 1);
  for (int i = 1; i <= n; i++)
    cin >> v[i];

  printWithPrecision(solve(v, n, (n + 1) / 2ll));
  return 0;
}


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

using namespace std;

typedef long long ll;
#define printWithPrecision(x) cout << fixed << setprecision(10) << x << endl;
double dp[3001][3001];

double solve(vector<double> &v, ll i, ll 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] = (v[i] * solve(v, i - 1, x - 1)) +
                    (((double)1 - v[i]) * solve(v, i - 1, x));
}

void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main() {
  fast();
  ll n;
  cin >> n;
  memset(dp, -1, sizeof dp);

  vector<double> v(n + 1);
  for (int i = 1; i <= n; i++)
    cin >> v[i];

  printWithPrecision(solve(v, n, (n + 1) / 2ll));
  return 0;
}
Problem p03168 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007;
vector<vector<double>> dp; // dp(i,j) probablity of coming j heads when i coins
vector<double> p;

double probhead(int n, int heads) {

  if (dp[n][heads] != -1) {
    return dp[n][heads];
  }
  return probhead(n - 1, heads) * (1 - p[n]) +
         probhead(n - 1, heads - 1) * p[n];
}
void solve() {
  int n;
  cin >> n;
  dp.resize(n + 1, vector<double>(n + 1, -1));
  p.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
  }
  for (int i = 0; i <= n; i++) {
    dp[0][i] = 0;
  }
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    dp[i][0] = dp[i - 1][0] * (1 - p[i]);
  }

  double pr = 0;
  for (int i = (n + 1) / 2; i <= n; i++) {
    pr += probhead(n, i);
  }
  cout << pr << "\n";
}

int main() {
  cin.tie(0);
  cout.tie(0);
  cin.sync_with_stdio(0);
  cout.sync_with_stdio(0);

  cout.precision(10);
  int t = 1; // cin>>t;
  while (t--) {

    solve();
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007;
vector<vector<double>> dp; // dp(i,j) probablity of coming j heads when i coins
vector<double> p;

double probhead(int n, int heads) {

  if (dp[n][heads] != -1) {
    return dp[n][heads];
  }
  return dp[n][heads] = probhead(n - 1, heads) * (1 - p[n]) +
                        probhead(n - 1, heads - 1) * p[n];
}
void solve() {
  int n;
  cin >> n;
  dp.resize(n + 1, vector<double>(n + 1, -1));
  p.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
  }
  for (int i = 0; i <= n; i++) {
    dp[0][i] = 0;
  }
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    dp[i][0] = dp[i - 1][0] * (1 - p[i]);
  }

  double pr = 0;
  for (int i = (n + 1) / 2; i <= n; i++) {
    pr += probhead(n, i);
  }
  cout << pr << "\n";
}

int main() {
  cin.tie(0);
  cout.tie(0);
  cin.sync_with_stdio(0);
  cout.sync_with_stdio(0);

  cout.precision(10);
  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;
#define int long long
#define f(i, x, n) for (int i = x; i < n; i++)
#define all(c) c.begin(), c.end()
const int MOD = 1e9 + 7, N = 2e3 + 10;
const int LINF = LLONG_MAX;
double dp[N][N];
double C[N];
int n;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << setprecision(10) << fixed;
  memset(dp, 0, sizeof(dp));
  cin >> n;
  f(i, 0, n) { cin >> C[i]; }
  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i; j++) {
      dp[i + 1][j + 1] += dp[i][j] * C[i];
      dp[i + 1][j] += dp[i][j] * (1 - C[i]);
    }
  }
  double ans = 0;
  for (int j = (n + 1) / 2; j <= n; j++) {
    ans += dp[n][j];
  }
  cout << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(i, x, n) for (int i = x; i < n; i++)
#define all(c) c.begin(), c.end()
const int MOD = 1e9 + 7, N = 3e3 + 10;
const int LINF = LLONG_MAX;
double dp[N][N];
double C[N];
int n;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << setprecision(10) << fixed;
  memset(dp, 0, sizeof(dp));
  cin >> n;
  f(i, 0, n) { cin >> C[i]; }
  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i; j++) {
      dp[i + 1][j + 1] += dp[i][j] * C[i];
      dp[i + 1][j] += dp[i][j] * (1 - C[i]);
    }
  }
  double ans = 0;
  for (int j = (n + 1) / 2; j <= n; j++) {
    ans += dp[n][j];
  }
  cout << ans;
  return 0;
}
Problem p03168 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <iostream>

using namespace std;

#define ll long long
#define pb push_back
#define pf push_front
#define loop(i, n) for (int i = 0; i < n; ++i)
#define LOOP(i, a, b) for (int i = a; i < b; ++i)
#define max3(a, b, c) max(a, max(b, c))
#define max4(a, b, c, d) max3(a, b, max(c, d))
#define ff first
#define ss second
#define mkp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vii vector<pii>
#define vvii vector<vii>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define nmbr(c) (int)(c - '0')
#define ltr(c) (int)(c - 'a')
#define INF 1e18
#define inf 1e9
#define MOD 1000000007 // check
#define _69e27                                                                 \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)

int n;
long double dp[3001][3001], p[3000];
bool dpb[3001][3001];

long double prb(int i, int h) {
  if (i == n)
    return (2 * h > n);
  long double &ans = dp[i][h];
  if (dpb[i][h])
    return ans;
  return ans = p[i] * prb(i + 1, h + 1) + (1 - p[i]) * prb(i + 1, h);
}
int main() {
  _69e27;
  memset(dpb, 0, sizeof(dpb));
  cin >> n;
  loop(i, n) cin >> p[i];
  cout << fixed << setprecision(10) << prb(0, 0);
  return 0;
}

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

using namespace std;

#define ll long long
#define pb push_back
#define pf push_front
#define loop(i, n) for (int i = 0; i < n; ++i)
#define LOOP(i, a, b) for (int i = a; i < b; ++i)
#define max3(a, b, c) max(a, max(b, c))
#define max4(a, b, c, d) max3(a, b, max(c, d))
#define ff first
#define ss second
#define mkp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vii vector<pii>
#define vvii vector<vii>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define nmbr(c) (int)(c - '0')
#define ltr(c) (int)(c - 'a')
#define INF 1e18
#define inf 1e9
#define MOD 1000000007 // check
#define _69e27                                                                 \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)

int n;
long double dp[3001][3001], p[3000];
bool dpb[3001][3001];

long double prb(int i, int h) {
  if (i == n)
    return (2 * h > n);
  long double &ans = dp[i][h];
  if (dpb[i][h])
    return ans;
  dpb[i][h] = 1;
  return ans = p[i] * prb(i + 1, h + 1) + (1 - p[i]) * prb(i + 1, h);
}
int main() {
  _69e27;
  memset(dpb, 0, sizeof(dpb));
  cin >> n;
  loop(i, n) cin >> p[i];
  cout << fixed << setprecision(10) << prb(0, 0);
  return 0;
}
Problem p03168 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fastio()                                                               \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define show(x) cout << (#x) << " : " << x << endl;
#define ll long long
#define ld long double

#define mp make_pair
#define ff first
#define ss second
#define pii pair<ll, ll>
#define sq(x) ((x) * (x))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
const ll MOD = 1000 * 1000 * 1000 + 7;
using namespace std;

long double dp[4000][4000];

ll N;

long double P[4000];

long double seno(ll idx, ll H) {

  if (idx == 1) {
    if (H == 0)
      return dp[idx][0] = 1 - P[idx];
    else
      return dp[idx][1] = P[idx];
  }

  if (dp[idx][H] != 4)
    return dp[idx][H];

  dp[idx][H] =
      (long double)(P[idx] * seno(idx - 1, H - 1)) +
      (long double)((idx - 1 - H >= 0 ? (1 - P[idx]) * seno(idx - 1, H) : 0));

  return dp[idx][H];
}

int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  fastio();

  cin >> N;

  for (int i = N; i >= 1; i--)
    cin >> P[i];

  for (int i = 1; i <= 3000; i++) {
    for (int j = 1; j <= 3000; j++)
      dp[i][j] = 4;
  }

  dp[1][0] = 1 - P[1];

  for (int i = 2; i <= N; i++) {
    dp[i][0] = (1 - P[i]) * dp[i - 1][0];
  }

  long double sum = 0;

  for (int i = (N / 2) + 1; i <= N; i++) {

    sum += seno(N, i);
  }

  cout << setprecision(9) << sum;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define fastio()                                                               \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define show(x) cout << (#x) << " : " << x << endl;
#define ll long long
#define ld long double

#define mp make_pair
#define ff first
#define ss second
#define pii pair<ll, ll>
#define sq(x) ((x) * (x))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
const ll MOD = 1000 * 1000 * 1000 + 7;
using namespace std;

long double dp[4000][4000];

ll N;

long double P[4000];

long double seno(ll idx, ll H) {

  if (idx == 1) {
    if (H == 0)
      return dp[idx][0] = 1 - P[idx];
    else
      return dp[idx][1] = P[idx];
  }

  if (dp[idx][H] != 4)
    return dp[idx][H];

  dp[idx][H] =
      (long double)(P[idx] * seno(idx - 1, H - 1)) +
      (long double)((idx - 1 - H >= 0 ? (1 - P[idx]) * seno(idx - 1, H) : 0));

  return dp[idx][H];
}

int main() {

  fastio();

  cin >> N;

  for (int i = N; i >= 1; i--)
    cin >> P[i];

  for (int i = 1; i <= 3000; i++) {
    for (int j = 1; j <= 3000; j++)
      dp[i][j] = 4;
  }

  dp[1][0] = 1 - P[1];

  for (int i = 2; i <= N; i++) {
    dp[i][0] = (1 - P[i]) * dp[i - 1][0];
  }

  long double sum = 0;

  for (int i = (N / 2) + 1; i <= N; i++) {

    sum += seno(N, i);
  }

  cout << setprecision(9) << sum;

  return 0;
}
Problem p03168 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll N;
double dp[3099][3099], p[3099], head[3099], tail[3099];

double f(ll n, ll m) {
  if (n == 0) {
    if (m == 0)
      return 1;
    else
      return 0;
  }
  if (m == 0) {
    return tail[n];
  }
  if (m == n) {
    return head[n];
  }
  if (dp[n][m] < 0)
    return dp[n][m];
  dp[n][m] = p[n] * f(n - 1, m - 1) + (1 - p[n]) * f(n - 1, m);
  return dp[n][m];
}

int main() {
  cin >> N;
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= N; i++) {
    cin >> p[i];
  }
  head[1] = p[1];
  tail[1] = 1 - p[1];
  for (int i = 2; i <= N; i++) {
    head[i] = p[i] * head[i - 1];
    tail[i] = (1 - p[i]) * tail[i - 1];
  }
  double jwb = 0;
  for (int i = (N + 1) / 2; i <= N; i++) {
    jwb += f(N, i);
  }
  cout << fixed << setprecision(10) << jwb << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll N;
double dp[3099][3099], p[3099], head[3099], tail[3099];

double f(ll n, ll m) {
  if (n == 0) {
    if (m == 0)
      return 1;
    else
      return 0;
  }
  if (m == 0) {
    return tail[n];
  }
  if (m == n) {
    return head[n];
  }
  if (dp[n][m] > -1)
    return dp[n][m];
  dp[n][m] = p[n] * f(n - 1, m - 1) + (1 - p[n]) * f(n - 1, m);
  return dp[n][m];
}

int main() {
  cin >> N;
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= N; i++) {
    cin >> p[i];
  }
  head[1] = p[1];
  tail[1] = 1 - p[1];
  for (int i = 2; i <= N; i++) {
    head[i] = p[i] * head[i - 1];
    tail[i] = (1 - p[i]) * tail[i - 1];
  }
  double jwb = 0;
  for (int i = (N + 1) / 2; i <= N; i++) {
    jwb += f(N, i);
  }
  cout << fixed << setprecision(10) << jwb << endl;
}
Problem p03168 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

// #define FILE_INPUT
// #define DEBUG_MODE

void DebugPrint(double a[], int n) {
#ifdef DEBUG_MODE
  for (int i = 0; i < min(20, n); ++i) {
    cout << a[i] << ",";
  }
  cout << endl;
#endif
}

double dp[3000 / 2][3000];

int main() {
#ifdef FILE_INPUT
  ifstream in("test3.txt");
  cin.rdbuf(in.rdbuf());
#endif /* FILE_INPUT */

  int n;
  cin >> n;

  vector<double> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }

  dp[0][0] = 1.0;

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

  double sum = 0.0;
  for (int i = 0; i < n / 2 + 1; ++i) {
    sum += dp[i][n];
  }

  cout << fixed << setprecision(10) << sum << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

// #define FILE_INPUT
// #define DEBUG_MODE

void DebugPrint(double a[], int n) {
#ifdef DEBUG_MODE
  for (int i = 0; i < min(20, n); ++i) {
    cout << a[i] << ",";
  }
  cout << endl;
#endif
}

double dp[2999 / 2 + 2][2999 + 1];

int main() {
#ifdef FILE_INPUT
  ifstream in("test3.txt");
  cin.rdbuf(in.rdbuf());
#endif /* FILE_INPUT */

  int n;
  cin >> n;

  vector<double> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }

  dp[0][0] = 1.0;

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

  double sum = 0.0;
  for (int i = 0; i < n / 2 + 1; ++i) {
    sum += dp[i][n];
  }

  cout << fixed << setprecision(10) << sum << endl;
  return 0;
}
Problem p03168 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("O3")
#pragma GCC target("avx")
// #include<bits/stdc++.h>
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 14;
char cn[cm], *ci = cn, ct;
const double p = 0.01;

int main() {
  // cin.tie(0);
  // ios::sync_with_stdio(false);

  fread(ci, 1, cm, stdin);

  int N = 0;
  while ((ct = *ci++) >= '0')
    N = N * 10 + ct - '0';

  int M = N / 2;
  vector<double> dp(M + 1);
  dp[0] = 1.0;

  rep(i, N) {
    ci += 2;
    int k = (*ci++ - '0') * 10;
    k += *ci++ - '0';
    double P = p * k;
    ci++;

    for (int j = min(M, i); j >= max(0, i - M); j--) {
      dp[j + 1] += dp[j] * P;
      dp[j] *= 1 - P;
    }
  }

  printf("%.15f", dp[M + 1]);

  Would you please return 0;
}

Fixed submission:
#pragma GCC optimize("O3")
#pragma GCC target("avx")
// #include<bits/stdc++.h>
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 14;
char cn[cm], *ci = cn, ct;
const double p = 0.01;

int main() {
  // cin.tie(0);
  // ios::sync_with_stdio(false);

  fread(ci, 1, cm, stdin);

  int N = 0;
  while ((ct = *ci++) >= '0')
    N = N * 10 + ct - '0';

  int M = N / 2;
  vector<double> dp(M + 2);
  dp[0] = 1.0;

  rep(i, N) {
    ci += 2;
    int k = (*ci++ - '0') * 10;
    k += *ci++ - '0';
    double P = p * k;
    ci++;

    for (int j = min(M, i); j >= max(0, i - M); j--) {
      dp[j + 1] += dp[j] * P;
      dp[j] *= 1 - P;
    }
  }

  printf("%.15f", dp[M + 1]);

  Would you please return 0;
}
Problem p03168 (C++)

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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template <typename T> ostream &operator<<(ostream &o, vector<T> &v) {
  for (auto &x : v)
    o << x << ' ';
  return o;
}
int n;
double arr[1010];
double memo[1010][1010];
double dp(int i, int heads) {
  double &res = memo[i][heads];
  if (res == res)
    return res;
  if (i == n)
    return (heads == 0) ? 1.0 : 0.0;
  res = arr[i] * dp(i + 1, heads - 1) + (1 - arr[i]) * dp(i + 1, heads);
  return res;
}

int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  memset(memo, -1, sizeof memo);
  double prob = 0.0;
  for (int i = n / 2 + 1; i <= n; i++) {
    prob += dp(0, i);
  }
  cout << fixed << setprecision(10) << prob << endl;
}


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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template <typename T> ostream &operator<<(ostream &o, vector<T> &v) {
  for (auto &x : v)
    o << x << ' ';
  return o;
}
int n;
double arr[3030];
double memo[3030][3030];
double dp(int i, int heads) {
  double &res = memo[i][heads];
  if (res == res)
    return res;
  if (i == n)
    return (heads == 0) ? 1.0 : 0.0;
  res = arr[i] * dp(i + 1, heads - 1) + (1 - arr[i]) * dp(i + 1, heads);
  return res;
}

int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  memset(memo, -1, sizeof memo);
  double prob = 0.0;
  for (int i = n / 2 + 1; i <= n; i++) {
    prob += dp(0, i);
  }
  cout << fixed << setprecision(10) << prob << endl;
}
Problem p03168 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#include <vector>
#define DEBUG 0
constexpr int kMax = 301;

int main() {
  int N;
  std::cin >> N;
  std::vector<double> p(N + 1);
  for (int i = 1; i <= N; ++i)
    std::cin >> p[i];

  double dp[kMax][kMax];

  dp[0][0] = 1.0;
  for (int j = 1; j <= N; ++j) {
    dp[0][j] = 0.0;
  }

#if DEBUG
  for (int j = 0; j <= N; ++j) {
    std::cout << dp[0][j] << "\t";
  }
  std::cout << std::endl;
#endif

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

#if DEBUG
    for (int j = 0; j <= N; ++j) {
      std::cout << dp[i][j] << "\t";
    }
    std::cout << std::endl;
#endif
  }

  double sum_p = 0.0;
  for (int j = N; j > N / 2; --j) {
    sum_p += dp[N][j];
  }
  printf("%.10f\n", sum_p);
}


Fixed submission:
#include <cstdio>
#include <iostream>
#include <vector>
#define DEBUG 0
constexpr int kMax = 3001;

int main() {
  int N;
  std::cin >> N;
  std::vector<double> p(N + 1);
  for (int i = 1; i <= N; ++i)
    std::cin >> p[i];

  double dp[kMax][kMax];

  dp[0][0] = 1.0;
  for (int j = 1; j <= N; ++j) {
    dp[0][j] = 0.0;
  }

#if DEBUG
  for (int j = 0; j <= N; ++j) {
    std::cout << dp[0][j] << "\t";
  }
  std::cout << std::endl;
#endif

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

#if DEBUG
    for (int j = 0; j <= N; ++j) {
      std::cout << dp[i][j] << "\t";
    }
    std::cout << std::endl;
#endif
  }

  double sum_p = 0.0;
  for (int j = N; j > N / 2; --j) {
    sum_p += dp[N][j];
  }
  printf("%.10f\n", sum_p);
}
Problem p03168 (C++)

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

#define all(v) v.begin(), v.end()
#define nl "\n"
#define IOI return 0;
#define pb push_back
#define ll long long
#define ld long double
#define IOS                                                                    \
  ios_base ::sync_with_stdio(NULL);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pii pair<int, int>
#define X first
#define Y second

using namespace std;
const int N = (int)2e5 + 7;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const int UNDEF = -1;

pii dx[] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

double p[301];
double dp[301];
int main() {
  IOS
      // freopen("lepus.in", "r", stdin);
      // freopen("lepus.out", "w", stdout);
      int n;
  cin >> n;
  for (int i = 1; i <= n; ++i)
    cin >> p[i];
  dp[0] = 1.0;
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j >= 0; --j) {
      dp[j] = dp[j - 1] * p[i] + dp[j] * (1.0 - p[i]);
    }
  }
  double ans = 0.0;
  for (int i = 0; i <= n; ++i) {
    if (i > n - i) {
      ans += dp[i];
    }
  }
  cout << setprecision(9) << fixed << ans;
  IOI
}


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

#define all(v) v.begin(), v.end()
#define nl "\n"
#define IOI return 0;
#define pb push_back
#define ll long long
#define ld long double
#define IOS                                                                    \
  ios_base ::sync_with_stdio(NULL);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pii pair<int, int>
#define X first
#define Y second

using namespace std;
const int N = (int)2e5 + 7;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const int UNDEF = -1;

pii dx[] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

double p[3001];
double dp[3001];
int main() {
  IOS
      // freopen("lepus.in", "r", stdin);
      // freopen("lepus.out", "w", stdout);
      int n;
  cin >> n;
  for (int i = 1; i <= n; ++i)
    cin >> p[i];
  dp[0] = 1.0;
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j >= 0; --j) {
      dp[j] = dp[j - 1] * p[i] + dp[j] * (1.0 - p[i]);
    }
  }
  double ans = 0.0;
  for (int i = 0; i <= n; ++i) {
    if (i > n - i) {
      ans += dp[i];
    }
  }
  cout << setprecision(9) << fixed << ans;
  IOI
}
Problem p03168 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define mt make_tuple
#define pb push_back
const int N = 1e3 + 10;
double dp[N][N], p[N];

int main() {
  int n;
  double ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> p[i];
  for (int i = 0; i <= n; i++)
    dp[0][i] = 0;
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= n; 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 = (n / 2) + 1; i <= n; i++)
    ans += dp[n][i];
  cout.precision(12);
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define mt make_tuple
#define pb push_back
const int N = 3010;
double dp[N][N], p[N];

int main() {
  int n;
  double ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> p[i];
  for (int i = 0; i <= n; i++)
    dp[0][i] = 0;
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= n; 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 = (n / 2) + 1; i <= n; i++)
    ans += dp[n][i];
  cout.precision(12);
  cout << ans << endl;
  return 0;
}
Problem p03168 (C++)

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

double dp[110][110];

int main() {
  int n;
  cin >> n;
  vector<double> p(n + 1);
  for (int i = 1; i <= n; i++)
    cin >> p[i];

  for (int i = 0; i <= n; i++)
    dp[0][i] = 1;

  for (int i = 1; i <= n; i++)
    for (int x = 0; x <= i; x++)
      if (!x)
        dp[x][i] = (1 - p[i]) * dp[x][i - 1];
      else
        dp[x][i] = (1 - p[i]) * dp[x][i - 1] + p[i] * dp[x - 1][i - 1];

  double ans = 0;

  for (int x = 1; x <= n; x++)
    if (x + x > n)
      ans += dp[x][n];

  printf("%.9lf\n", ans);

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

double dp[3001][3001];

int main() {
  int n;
  cin >> n;
  vector<double> p(n + 1);
  for (int i = 1; i <= n; i++)
    cin >> p[i];

  for (int i = 0; i <= n; i++)
    dp[0][i] = 1;

  for (int i = 1; i <= n; i++)
    for (int x = 0; x <= i; x++)
      if (!x)
        dp[x][i] = (1 - p[i]) * dp[x][i - 1];
      else
        dp[x][i] = (1 - p[i]) * dp[x][i - 1] + p[i] * dp[x - 1][i - 1];

  double ans = 0;

  for (int x = 1; x <= n; x++)
    if (x + x > n)
      ans += dp[x][n];

  printf("%.9lf\n", ans);

  return 0;
}
Problem p03168 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 100;
int n;
double a[maxn], dp[maxn][maxn];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      dp[i][j] += dp[i - 1][j - 1] * a[i];
    }
    for (int j = 0; j <= i; j++) {
      dp[i][j] += dp[i - 1][j] * (1 - a[i]);
    }
  }
  double ans = 0;
  for (int i = 1; i <= n; i++) {
    if (i > n - i)
      ans += dp[n][i];
  }
  printf("%.20f\n", ans);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e3 + 100;
int n;
double a[maxn], dp[maxn][maxn];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      dp[i][j] += dp[i - 1][j - 1] * a[i];
    }
    for (int j = 0; j <= i; j++) {
      dp[i][j] += dp[i - 1][j] * (1 - a[i]);
    }
  }
  double ans = 0;
  for (int i = 1; i <= n; i++) {
    if (i > n - i)
      ans += dp[n][i];
  }
  printf("%.20f\n", ans);
}
Problem p03168 (C++)

Buggy submission (status: Runtime Error):
#include <cassert>
#include <cstdio>
int n, licz;
long double start;
long double tab[3003][3003];
long double res;

long double chance(int t, long double x, long double y) {
  if (t == 0)
    return (1.0 - x) * (1.0 - y);
  if (t == 1)
    return 1.0 - (1.0 - x) * (1.0 - y) - x * y;
  else
    return x * y;
}

// 0 -> -n/2
// 1 -> -n/2+1
// n/2 -> -1
// n/2+1 -> 1...

int main() {

  scanf("%d", &n);
  scanf("%Lf", &start);
  tab[0][n / 2] = 1.0 - start;
  tab[0][n / 2 + 1] = start;

  for (int i = 0; i < n / 2; i++) {
    ++licz;
    long double x, y;
    scanf("%Lf %Lf", &x, &y);

    tab[licz][0] =
        tab[licz - 1][0] * chance(1, x, y) + tab[licz - 1][1] * chance(0, x, y);
    for (int j = 1; j <= n; j++) {
      tab[licz][j] = tab[licz - 1][j - 1] * chance(2, x, y) +
                     tab[licz - 1][j] * chance(1, x, y) +
                     tab[licz - 1][j + 1] * chance(0, x, y);
    }
  }
  for (int i = n / 2 + 1; i <= n; i++) {
    res += tab[licz][i];
  }
  assert(res <= 1);
  printf("%.10Lf\n", res);
}


Fixed submission:
#include <cassert>
#include <cstdio>
int n, licz;
long double start;
long double tab[3003][3003];
long double res;

long double chance(int t, long double x, long double y) {
  if (t == 0)
    return (1.0 - x) * (1.0 - y);
  if (t == 1)
    return 1.0 - (1.0 - x) * (1.0 - y) - x * y;
  else
    return x * y;
}

// 0 -> -n/2
// 1 -> -n/2+1
// n/2 -> -1
// n/2+1 -> 1...

int main() {

  scanf("%d", &n);
  scanf("%Lf", &start);
  tab[0][n / 2] = 1.0 - start;
  tab[0][n / 2 + 1] = start;

  for (int i = 0; i < n / 2; i++) {
    ++licz;
    long double x, y;
    scanf("%Lf %Lf", &x, &y);

    tab[licz][0] =
        tab[licz - 1][0] * chance(1, x, y) + tab[licz - 1][1] * chance(0, x, y);
    for (int j = 1; j <= n; j++) {
      tab[licz][j] = tab[licz - 1][j - 1] * chance(2, x, y) +
                     tab[licz - 1][j] * chance(1, x, y) +
                     tab[licz - 1][j + 1] * chance(0, x, y);
    }
  }
  for (int i = n / 2 + 1; i <= n; i++) {
    res += tab[licz][i];
  }
  // assert(res<=1);
  printf("%.10Lf\n", res);
}
Problem p03168 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int n;
const int MAX = 3010;
double moedas[MAX];
double memo[MAX][MAX];

double pd(int i, int k) {
  if (i >= n)
    return k >= (n / 2 + 1);
  if (memo[i][k] != -1.0)
    return memo[i][k];
  return ((1.0 - moedas[i]) * pd(i + 1, k)) + (moedas[i] * pd(i + 1, k + 1));
}

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      memo[i][j] = -1.0;
    }
  }
  for (int i = 0; i < n; ++i) {
    cin >> moedas[i];
  }
  double ans = pd(0, 0);
  printf("%.10f\n", ans);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int n;
const int MAX = 3010;
double moedas[MAX];
double memo[MAX][MAX];

double pd(int i, int k) {
  if (i >= n)
    return k >= (n / 2 + 1);
  if (memo[i][k] != -1.0)
    return memo[i][k];
  return memo[i][k] = ((1.0 - moedas[i]) * pd(i + 1, k)) +
                      (moedas[i] * pd(i + 1, k + 1));
}

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      memo[i][j] = -1.0;
    }
  }
  for (int i = 0; i < n; ++i) {
    cin >> moedas[i];
  }
  double ans = pd(0, 0);
  printf("%.10f\n", ans);
}
Problem p03168 (C++)

Buggy submission (status: Runtime Error):


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define sp(x) fixed << setprecision(x)
#define fast_io                                                                \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
using namespace std;

// vector<vector<double>> dp(3001,vector<double>(3001,-1));
double dp[3001][3001];
double fun(vector<double> &p, int i, int atleast_heads) {
  // Base case
  if (atleast_heads == 0)
    return 1;

  if (i == 0)
    return 0;

  // Lookup
  if (dp[i][atleast_heads] > -0.9)
    return dp[i][atleast_heads];

  // Rec case
  // double op1 = p[i]*fun(p,i-1,atleast_heads-1);
  // double op2 = (1-p[i])*fun(p,i-1,atleast_heads);
  return dp[i][atleast_heads] = p[i] * fun(p, i - 1, atleast_heads - 1) +
                                (1 - p[i]) * fun(p, i - 1, atleast_heads);
}

int main() {
  fast_io;

  memset(dp, -1, sizeof(dp));
  int n;
  cin >> n;
  vector<double> p(n);

  for (int i = 1; i <= n; i++)
    cin >> p[i];

  cout << sp(10) << fun(p, n, (n + 1) / 2) << endl;

  return 0;
}

Fixed submission:


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define sp(x) fixed << setprecision(x)
#define fast_io                                                                \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
using namespace std;

// vector<vector<double>> dp(3001,vector<double>(3001,-1));
double dp[3001][3001];
double fun(vector<double> &p, int i, int atleast_heads) {
  // Base case
  if (atleast_heads == 0)
    return 1;

  if (i == 0)
    return 0;

  // Lookup
  if (dp[i][atleast_heads] > -0.9)
    return dp[i][atleast_heads];

  // Rec case
  // double op1 = p[i]*fun(p,i-1,atleast_heads-1);
  // double op2 = (1-p[i])*fun(p,i-1,atleast_heads);
  return dp[i][atleast_heads] = p[i] * fun(p, i - 1, atleast_heads - 1) +
                                (1 - p[i]) * fun(p, i - 1, atleast_heads);
}

int main() {
  fast_io;

  memset(dp, -1, sizeof(dp));
  int n;
  cin >> n;
  vector<double> p(n + 1);

  for (int i = 1; i <= n; i++)
    cin >> p[i];

  cout << sp(10) << fun(p, n, (n + 1) / 2) << endl;

  return 0;
}
Problem p03168 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

#define INF (1 << 29)
#define INFF 0x7fffffff
#define LINF (1ll << 60)
#define LINFF 0x7fffffffffffffff
#define PI 3.14159265359

#define _fi(n) for (int i = 0; i < n; i++)
#define _fj(n) for (int j = 0; j < n; j++)
#define _fk(n) for (int k = 0; k < n; k++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define prec(x) cout << fixed << setprecision(x)

#define hash sodnf9843bsd
#define ll long long
#define pqueue priority_queue
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define endl '\n'

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll a, ll b) { return uniform_int_distribution<ll>(a, b)(rng); }

int n;
double p[3003] = {};
double dp[3003][3003] = {};
bool vis[3003][3003] = {};
double full = 1;

double solve(int i, int j) {
  if (i == n) {
    if (j > n / 2)
      return 1;
    return 0;
  }

  if (vis[i][j] == false) {
    dp[i][j] = (1. - p[i]) * solve(i + 1, j) + p[i] * solve(i + 1, j + 1);
  }
  return dp[i][j];
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> n;
  _fi(n) {
    cin >> p[i];
    full *= p[i];
  }

  prec(10);
  cout << solve(0, 0) << endl;

  return 0;
}


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

using namespace std;

#define INF (1 << 29)
#define INFF 0x7fffffff
#define LINF (1ll << 60)
#define LINFF 0x7fffffffffffffff
#define PI 3.14159265359

#define _fi(n) for (int i = 0; i < n; i++)
#define _fj(n) for (int j = 0; j < n; j++)
#define _fk(n) for (int k = 0; k < n; k++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define prec(x) cout << fixed << setprecision(x)

#define hash sodnf9843bsd
#define ll long long
#define pqueue priority_queue
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define endl '\n'

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll a, ll b) { return uniform_int_distribution<ll>(a, b)(rng); }

int n;
double p[3003] = {};
double dp[3003][3003] = {};
bool vis[3003][3003] = {};
double full = 1;

double solve(int i, int j) {
  if (i == n) {
    if (j > n / 2)
      return 1;
    return 0;
  }

  if (vis[i][j] == false) {
    vis[i][j] = true;
    dp[i][j] = (1. - p[i]) * solve(i + 1, j) + p[i] * solve(i + 1, j + 1);
  }
  return dp[i][j];
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> n;
  _fi(n) {
    cin >> p[i];
    full *= p[i];
  }

  prec(10);
  cout << solve(0, 0) << endl;

  return 0;
}
Problem p03168 (C++)

Buggy submission (status: Time Limit Exceeded):
/* "miles to go before I sleep." */

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

typedef long long ll;
#define mod 1000000007
#define pi 3.14159265358979323846
#define pb push_back
#define mk make_pair
#define popcnt(a)                                                              \
  _Generic((a), int                                                            \
           : __builtin_popcount(a), \ long long                                \
           : __builtin_popcountll(a))
#define precise(x) cout << fixed << setprecision(10) << x
#define test cout << "#";
#define input freopen("input.txt", "r", stdin)
#define output freopen("output.txt", "w", stdout)

const ll inf = 1e18L + 2;

double dp[3001][3001];

double solve(vector<double> &v, ll n, ll x) {
  if (x == 0)
    return 1;
  if (n == 0)
    return 0;
  if (dp[n][x] >= -0.9)
    dp[n][x];
  return dp[n][x] = solve(v, n - 1, x - 1) * v[n - 1] +
                    solve(v, n - 1, x) * (1 - v[n - 1]);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll n;
  cin >> n;
  vector<double> v(n);
  for (ll x = 0; x < n; x++)
    cin >> v[x];
  memset(dp, -1, sizeof(dp));
  precise(solve(v, n, (n + 2) / 2));
}

Fixed submission:
/* "miles to go before I sleep." */

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

typedef long long ll;
#define mod 1000000007
#define pi 3.14159265358979323846
#define pb push_back
#define mk make_pair
#define popcnt(a)                                                              \
  _Generic((a), int                                                            \
           : __builtin_popcount(a), \ long long                                \
           : __builtin_popcountll(a))
#define precise(x) cout << fixed << setprecision(10) << x
#define test cout << "#";
#define input freopen("input.txt", "r", stdin)
#define output freopen("output.txt", "w", stdout)

const ll inf = 1e18L + 2;

double dp[3001][3001];

double solve(vector<double> &v, ll n, ll x) {
  if (x == 0)
    return 1;
  if (n == 0)
    return 0;
  if (dp[n][x] >= -0.9)
    return dp[n][x];
  return dp[n][x] = solve(v, n - 1, x - 1) * v[n - 1] +
                    solve(v, n - 1, x) * (1 - v[n - 1]);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll n;
  cin >> n;
  vector<double> v(n);
  for (ll x = 0; x < n; x++)
    cin >> v[x];
  memset(dp, -1, sizeof(dp));
  precise(solve(v, n, (n + 2) / 2));
}
Problem p03168 (C++)

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

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  vector<double> p(n, 0);
  vector<vector<double>> pb =
      vector<vector<double>>(n + 1, vector<double>(n + 1, 0));
  pb[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%lf", &p[i]);
    for (int j = 0; j < i; j++) {
      if (pb[i - 1][j] <= 1e-14) {
        continue;
      }
      pb[i][j] += pb[i - 1][j] * (1 - p[i]);
      pb[i][j + 1] += pb[i - 1][j] * p[i];
    }
  }
  double r = 0;
  for (int j = n / 2 + 1; j <= n; j++) {
    r += pb[n][j];
  }
  printf("%.10lf", r);
  return 0;
}


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

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  vector<double> p(n + 1, 0);
  vector<vector<double>> pb =
      vector<vector<double>>(n + 1, vector<double>(n + 1, 0));
  pb[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%lf", &p[i]);
    for (int j = 0; j < i; j++) {
      if (pb[i - 1][j] <= 1e-14) {
        continue;
      }
      pb[i][j] += pb[i - 1][j] * (1 - p[i]);
      pb[i][j + 1] += pb[i - 1][j] * p[i];
    }
  }
  double r = 0;
  for (int j = n / 2 + 1; j <= n; j++) {
    r += pb[n][j];
  }
  printf("%.10lf", r);
  return 0;
}
Problem p03168 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#if defined __has_include
#if __has_include(<bits/debug_aamir.h>)
#define dbg(...) DEBUG(#__VA_ARGS__, __VA_ARGS__);
#include <bits/debug_aamir.h>
#else
#define dbg(...)
#endif
#endif

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
typedef pair<ll, ll> pll;
#define sz(x) int(x.size())
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define rep(i, begin, end) for (__typeof(end) i = begin; i < end; i++)
#define per(i, begin, end) for (__typeof(end) i = begin; i >= end; i--)
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 1e18 + 1;

template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

const int nax = 30005;
vector<vector<double>> dp(nax, vector<double>(nax));
vector<double> p(nax);

int main() {
  fastio;
  int n;
  cin >> n;
  rep(i, 0, n) cin >> p[i];
  dp[0][0] = 1 - p[0];
  dp[0][1] = p[0];
  rep(i, 0, n - 1) {
    rep(j, 0, n) {
      dp[i + 1][j] += dp[i][j] * (1 - p[i + 1]);
      dp[i + 1][j + 1] += dp[i][j] * p[i + 1];
    }
  }
  double ans = 0;
  rep(i, (n + 1) / 2, n + 1) ans += dp[n - 1][i];
  dbg(p);
  rep(i, 0, n) dbg(dp[i]);
  printf("%.10lf\n", ans);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#if defined __has_include
#if __has_include(<bits/debug_aamir.h>)
#define dbg(...) DEBUG(#__VA_ARGS__, __VA_ARGS__);
#include <bits/debug_aamir.h>
#else
#define dbg(...)
#endif
#endif

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
typedef pair<ll, ll> pll;
#define sz(x) int(x.size())
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define rep(i, begin, end) for (__typeof(end) i = begin; i < end; i++)
#define per(i, begin, end) for (__typeof(end) i = begin; i >= end; i--)
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 1e18 + 1;

template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

const int nax = 3005;
vector<vector<double>> dp(nax, vector<double>(nax));
vector<double> p(nax);

int main() {
  fastio;
  int n;
  cin >> n;
  rep(i, 0, n) cin >> p[i];
  dp[0][0] = 1 - p[0];
  dp[0][1] = p[0];
  rep(i, 0, n - 1) {
    rep(j, 0, n) {
      dp[i + 1][j] += dp[i][j] * (1 - p[i + 1]);
      dp[i + 1][j + 1] += dp[i][j] * p[i + 1];
    }
  }
  double ans = 0;
  rep(i, (n + 1) / 2, n + 1) ans += dp[n - 1][i];
  dbg(p);
  rep(i, 0, n) dbg(dp[i]);
  printf("%.10lf\n", ans);
}
Problem p03168 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i))
using ll = long long;
using namespace std;

#define INF ((1 << 30) - 1)
#define LLINF (1LL << 60)
#define EPS (1e-10)

// 分解

// dp[i][j] := i番目までのコインを投げて，表がちょうどj枚になる確率
double dp[3030][3030];

// dp[i][j] = dp[i-1][j-1] * p[j] + dp[i-1][j] * (1-p[j])
// 排反
// i枚目に表が出る確率 dp[i-1][j-1] * p[j]
// i枚目に裏が出る確率 dp[i-1][j] * (1 - p[j])

int main() {
  int N;
  cin >> N;
  vector<double> p(N);
  rep(i, N) cin >> p[i + 1];

  dp[0][0] = 1.0;
  for (int i = 1; i <= N; ++i) {
    for (int j = 0; j <= i; ++j) {
      if (j - 1 >= 0)
        dp[i][j] += dp[i - 1][j - 1] * p[i];
      dp[i][j] += dp[i - 1][j] * (1 - p[i]);
    }
  }
  double ans = 0;
  for (int i = 0; i <= N; ++i) {
    if (i > N - i)
      ans += dp[N][i];
  }
  printf("%.15lf\n", ans);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i))
using ll = long long;
using namespace std;

#define INF ((1 << 30) - 1)
#define LLINF (1LL << 60)
#define EPS (1e-10)

// 分解

// dp[i][j] := i番目までのコインを投げて，表がちょうどj枚になる確率
double dp[3030][3030];

// dp[i][j] = dp[i-1][j-1] * p[j] + dp[i-1][j] * (1-p[j])
// 排反
// i枚目に表が出る確率 dp[i-1][j-1] * p[j]
// i枚目に裏が出る確率 dp[i-1][j] * (1 - p[j])

int main() {
  int N;
  cin >> N;
  vector<double> p(N + 1);
  rep(i, N) cin >> p[i + 1];

  dp[0][0] = 1.0;
  for (int i = 1; i <= N; ++i) {
    for (int j = 0; j <= i; ++j) {
      if (j - 1 >= 0)
        dp[i][j] += dp[i - 1][j - 1] * p[i];
      dp[i][j] += dp[i - 1][j] * (1 - p[i]);
    }
  }
  double ans = 0;
  for (int i = 0; i <= N; ++i) {
    if (i > N - i)
      ans += dp[N][i];
  }
  printf("%.15lf\n", ans);
}
Problem p03168 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i))
using ll = long long;
using namespace std;

#define INF ((1 << 30) - 1)
#define LLINF (1LL << 60)
#define EPS (1e-10)

// どういうDPか
// dp[i][j] := i枚目のコインを投げたとき，表がj枚である確率

// 計算方法
// 1-index
// dp[0][0] = 1.0
// dp[i][j] = (dp[i-1][j-1] * p[i] + dp[i-1][j] * (1-p[i]))
// 表が出ることと，出なかったことで場合分け

// どういう順番
// 小さい順から
// j > N-j のときの総和

double dp[3030][3030];

int main() {
  int N;
  cin >> N;
  vector<double> p(N);
  rep(i, N) cin >> p[i + 1];

  dp[0][0] = 1.0;
  for (int i = 1; i <= N; ++i) {
    for (int j = 0; j <= N; ++j) {
      if (j > 0) {
        dp[i][j] += dp[i - 1][j - 1] * p[i];
      }
      dp[i][j] += dp[i - 1][j] * (1 - p[i]);
      // dp[i][j] = dp[i-1][j-1] * p[i] + dp[i-1][j] * (1 - p[i]);
    }
  }

  double ans = 0;
  for (int i = 0; i <= N; ++i) {
    if (i > N - i)
      ans += dp[N][i];
  }
  printf("%.10f\n", ans);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i))
using ll = long long;
using namespace std;

#define INF ((1 << 30) - 1)
#define LLINF (1LL << 60)
#define EPS (1e-10)

// どういうDPか
// dp[i][j] := i枚目のコインを投げたとき，表がj枚である確率

// 計算方法
// 1-index
// dp[0][0] = 1.0
// dp[i][j] = (dp[i-1][j-1] * p[i] + dp[i-1][j] * (1-p[i]))
// 表が出ることと，出なかったことで場合分け

// どういう順番
// 小さい順から
// j > N-j のときの総和

double dp[3030][3030];

int main() {
  int N;
  cin >> N;
  vector<double> p(N + 1);
  rep(i, N) cin >> p[i + 1];

  dp[0][0] = 1.0;
  for (int i = 1; i <= N; ++i) {
    for (int j = 0; j <= N; ++j) {
      if (j > 0) {
        dp[i][j] += dp[i - 1][j - 1] * p[i];
      }
      dp[i][j] += dp[i - 1][j] * (1 - p[i]);
      // dp[i][j] = dp[i-1][j-1] * p[i] + dp[i-1][j] * (1 - p[i]);
    }
  }

  double ans = 0;
  for (int i = 0; i <= N; ++i) {
    if (i > N - i)
      ans += dp[N][i];
  }
  printf("%.10f\n", ans);
}
Problem p03168 (C++)

Buggy submission (status: Runtime Error):
#include <iomanip>
#include <iostream>
using namespace std;

const long long MAXN = 1001;

double dp[MAXN][MAXN];
double p[MAXN];

int main() {
  int n;
  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 + 1] += dp[i][j] * p[i];
      dp[i + 1][j] += dp[i][j] * (1 - p[i]);
    }
  }
  double ans = 0;
  for (int i = (n + 1) / 2; i <= n; i++) {
    ans += dp[n][i];
  }
  cout << setprecision(10) << ans << endl;
}


Fixed submission:
#include <iomanip>
#include <iostream>
using namespace std;

const long long MAXN = 3001;

double dp[MAXN][MAXN];
double p[MAXN];

int main() {
  int n;
  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 + 1] += dp[i][j] * p[i];
      dp[i + 1][j] += dp[i][j] * (1 - p[i]);
    }
  }
  double ans = 0;
  for (int i = (n + 1) / 2; i <= n; i++) {
    ans += dp[n][i];
  }
  cout << setprecision(10) << ans << endl;
}