Problem p03083 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define int long long

const int N = 103;
const int MOD = 1e9 + 7;

int add(int a, int b) { return (a + b) % MOD; }

int mul(int a, int b) { return (a * b) % MOD; }

int sub(int a, int b) { return (a - b + MOD) % MOD; }

int binpow(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1)
      res = mul(res, a);
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

int divv(int a, int b) { return mul(a, binpow(b, MOD - 2)); }

int f[N];

void init() {
  f[0] = 1;
  for (int i = 1; i < N; i++) {
    f[i] = mul(i, f[i - 1]);
  }
}

int C(int n, int k) {
  if (k < 0 || k > n)
    return 0;
  return divv(f[n], mul(f[k], f[n - k]));
}

vector<int> dp_w;
vector<int> dp_b;

void calc_dp(int W, int B) {
  dp_w.resize(W + B + 1);
  dp_b.resize(W + B + 1);
  for (int i = min(W, B); i <= W + B; i++) {
    {
      dp_w[i] = dp_w[i - 1];
      dp_w[i] = add(dp_w[i], divv(C(i - 1, W - 1), binpow(2, i)));
    }
    {

      dp_b[i] = dp_b[i - 1];
      dp_b[i] = add(dp_b[i], divv(C(i - 1, B - 1), binpow(2, i)));
    }
  }
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  init();

  int w, b;
  cin >> b >> w;
  calc_dp(w, b);
  for (int i = 1; i <= w + b; i++) {
    int prob_end = dp_w[i - 1];
    int prob_ok = sub(1, add(dp_w[i - 1], dp_b[i - 1]));
    int ans = add(prob_end, divv(prob_ok, 2));
    cout << ans << '\n';
  }
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define int long long

const int N = 2e5 + 9;
const int MOD = 1e9 + 7;

int add(int a, int b) { return (a + b) % MOD; }

int mul(int a, int b) { return (a * b) % MOD; }

int sub(int a, int b) { return (a - b + MOD) % MOD; }

int binpow(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1)
      res = mul(res, a);
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

int divv(int a, int b) { return mul(a, binpow(b, MOD - 2)); }

int f[N];

void init() {
  f[0] = 1;
  for (int i = 1; i < N; i++) {
    f[i] = mul(i, f[i - 1]);
  }
}

int C(int n, int k) {
  if (k < 0 || k > n)
    return 0;
  return divv(f[n], mul(f[k], f[n - k]));
}

vector<int> dp_w;
vector<int> dp_b;

void calc_dp(int W, int B) {
  dp_w.resize(W + B + 1);
  dp_b.resize(W + B + 1);
  for (int i = min(W, B); i <= W + B; i++) {
    {
      dp_w[i] = dp_w[i - 1];
      dp_w[i] = add(dp_w[i], divv(C(i - 1, W - 1), binpow(2, i)));
    }
    {

      dp_b[i] = dp_b[i - 1];
      dp_b[i] = add(dp_b[i], divv(C(i - 1, B - 1), binpow(2, i)));
    }
  }
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  init();

  int w, b;
  cin >> b >> w;
  calc_dp(w, b);
  for (int i = 1; i <= w + b; i++) {
    int prob_end = dp_w[i - 1];
    int prob_ok = sub(1, add(dp_w[i - 1], dp_b[i - 1]));
    int ans = add(prob_end, divv(prob_ok, 2));
    cout << ans << '\n';
  }
}