Problem p03134 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <thread>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<double, ll> pdl;
#define F first
#define S second
const ll E = 1e18 + 7;
const ll MOD = 998244353; // 1000000007;

int main() {
  string s;
  cin >> s;
  vector<ll> cnt0, cnt1;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0') {
      cnt0.push_back(i);
      cnt0.push_back(i);
    } else if (s[i] == '1') {
      cnt0.push_back(i);
      cnt1.push_back(i);
    } else {
      cnt1.push_back(i);
      cnt1.push_back(i);
    }
  }
  vector<vector<ll>> dp(2 * s.size() + 1, vector<ll>(2 * s.size() + 1, 0));
  dp[0][0] = 1;
  for (int i = 0; i < 2 * s.size(); i++) {
    for (int t = 0; t < 2 * s.size(); t++) {
      if (cnt1.size() >= t + 1 && cnt1[t] <= i) {
        dp[i + 1][t + 1] += dp[i][t];
        dp[i + 1][t + 1] %= MOD;
      }
      if (cnt0.size() >= i - t + 1 && cnt0[i - t] <= i) {
        dp[i + 1][t] += dp[i][t];
        dp[i + 1][t] %= MOD;
      }
    }
  }
  ll sum = 0;
  for (int i = 0; i <= 2 * s.size(); i++) {
    sum += dp[2 * s.size()][i];
  }
  cout << sum % MOD << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <thread>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<double, ll> pdl;
#define F first
#define S second
const ll E = 1e18 + 7;
const ll MOD = 998244353; // 1000000007;

int main() {
  string s;
  cin >> s;
  vector<ll> cnt0, cnt1;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0') {
      cnt0.push_back(i);
      cnt0.push_back(i);
    } else if (s[i] == '1') {
      cnt0.push_back(i);
      cnt1.push_back(i);
    } else {
      cnt1.push_back(i);
      cnt1.push_back(i);
    }
  }
  vector<vector<ll>> dp(2 * s.size() + 1, vector<ll>(2 * s.size() + 1, 0));
  dp[0][0] = 1;
  for (int i = 0; i < 2 * s.size(); i++) {
    for (int t = 0; t < 2 * s.size(); t++) {
      if (cnt1.size() >= t + 1 && cnt1[t] <= i) {
        dp[i + 1][t + 1] += dp[i][t];
        dp[i + 1][t + 1] %= MOD;
      }
      if (cnt0.size() >= i - t + 1 && i - t >= 0 && cnt0[i - t] <= i) {
        dp[i + 1][t] += dp[i][t];
        dp[i + 1][t] %= MOD;
      }
    }
  }
  ll sum = 0;
  for (int i = 0; i <= 2 * s.size(); i++) {
    sum += dp[2 * s.size()][i];
  }
  cout << sum % MOD << endl;

  return 0;
}