Problem p02635 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set                                                            \
  tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
const int M = 302;
const int mod = 998244353;
int don[M][M], bor[M][M], dp[M][M];
void compute() {
  for (int j = 300; j >= 0; j--)
    for (int k = 300; k >= 0; k--)
      bor[j][k] = (dp[j][k] + bor[j + 1][k + 1]) % mod;
  for (int j = 0; j <= 300; j++) {
    for (int k = 0; k <= 300; k++) {
      don[j][k] = dp[j][k];
      if (j)
        don[j][k] = (don[j][k] + don[j - 1][k]) % mod;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  int K;
  cin >> K;
  if (s[sz(s) - 1] != '0')
    s = s + "0";
  std::vector<int> v;
  int c = 0;
  for (int i = 0; i < sz(s); i++) {
    if (s[i] == '0') {
      v.pb(c);
      c = 0;
    } else
      c++;
  }
  for (int i = 0; i <= K; i++)
    dp[0][i] = 1;
  compute();
  for (int i = sz(v) - 1; i >= 0; i--) {
    for (int j = 0; j <= 300; j++) {
      for (int k = 0; k <= 300; k++) {
        // borrow
        int a = bor[j + 1][k + 1];
        // donate
        int x = v[i];
        int b = don[j][k];
        if (j > x)
          b = (b - don[j - x - 1][k] + mod) % mod;
        dp[j][k] = (a + b) % mod;
      }
    }
    compute();
  }
  cout << dp[0][0] << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set                                                            \
  tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
const int M = 302;
const int mod = 998244353;
int don[M][M], bor[M][M], dp[M][M];
void compute() {
  for (int j = 300; j >= 0; j--)
    for (int k = 300; k >= 0; k--)
      bor[j][k] = (dp[j][k] + bor[j + 1][k + 1]) % mod;
  for (int j = 0; j <= 300; j++) {
    for (int k = 0; k <= 300; k++) {
      don[j][k] = dp[j][k];
      if (j)
        don[j][k] = (don[j][k] + don[j - 1][k]) % mod;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  int K;
  cin >> K;
  if (s[sz(s) - 1] != '0')
    s = s + "0";
  std::vector<int> v;
  int c = 0;
  for (int i = 0; i < sz(s); i++) {
    if (s[i] == '0') {
      v.pb(c);
      c = 0;
    } else
      c++;
  }
  for (int i = 0; i <= min(K, 300); i++)
    dp[0][i] = 1;
  compute();
  for (int i = sz(v) - 1; i >= 0; i--) {
    for (int j = 0; j <= 300; j++) {
      for (int k = 0; k <= 300; k++) {
        // borrow
        int a = bor[j + 1][k + 1];
        // donate
        int x = v[i];
        int b = don[j][k];
        if (j > x)
          b = (b - don[j - x - 1][k] + mod) % mod;
        dp[j][k] = (a + b) % mod;
      }
    }
    compute();
  }
  cout << dp[0][0] << "\n";
  return 0;
}