Problem p02635 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll, ll> prl;
typedef vector<ll> vcl;
typedef map<ll, ll> mapl;
typedef unordered_map<ll, ll> umap;
#define pb push_back
#define all(v) v.begin(), v.end()
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define repi(i, a, b) for (int i = a; i <= b; i++)
#define repr(i, a, b) for (ll i = a; i >= b; i--)
#define reps(i, v) for (ll i = 0; i < v.size(); i++)
template <typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template <typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 998244353;

int main() {
  // your code goes here
  ll k, n, pba = 0, os = 0, ans = 0;
  vcl v;
  string si;
  cin >> si >> k;
  chmin(k, 305ll);
  n = si.size();
  rep(i, 0, n - 1) {
    if (si[i] == '1') {
      pba++;
    } else {
      os++;
      v.pb(pba);
      pba = 0;
    }
  }
  v.pb(pba);
  n = v.size();
  ll dp[310][310] = {0}, lla[310][310] = {0}, r[310][310] = {0};
  rep(i, 0, k) { dp[i][0] = 1; }
  rep(j, 0, k) {
    rep(l, 0, j) { lla[j][l + 1] = (lla[j][l] + dp[j][l]) % mod; }
  }
  rep(l, 0, k) {
    rep(j, l, k) { r[j + 1][l] = (r[j][l] + dp[j][l]) % mod; }
  }
  rep(i, 1, n - 1) {
    rep(j, 0, k) {
      rep(l, 0, j) {
        dp[j][l] = (dp[j][l] + r[j][l] - r[l][l] + mod) % mod;
        dp[j][l] =
            (dp[j][l] + lla[j][l] - lla[j][max(0ll, l - v[i])] + mod) % mod;
      }
    }
    rep(j, 0, k) {
      rep(l, 0, j) { lla[j][l + 1] = (lla[j][l] + dp[j][l]) % mod; }
    }
    rep(l, 0, k) {
      rep(j, l, k) { r[j + 1][l] = (r[j][l] + dp[j][l]) % mod; }
    }
  }
  rep(i, 0, k) { ans = (ans + dp[i][i]) % mod; }
  cout << ans << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll, ll> prl;
typedef vector<ll> vcl;
typedef map<ll, ll> mapl;
typedef unordered_map<ll, ll> umap;
#define pb push_back
#define all(v) v.begin(), v.end()
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define repi(i, a, b) for (int i = a; i <= b; i++)
#define repr(i, a, b) for (ll i = a; i >= b; i--)
#define reps(i, v) for (ll i = 0; i < v.size(); i++)
template <typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template <typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 998244353;

int main() {
  // your code goes here
  ll k, n, pba = 0, os = 0, ans = 0;
  vcl v;
  string si;
  cin >> si >> k;
  chmin(k, 305ll);
  n = si.size();
  rep(i, 0, n - 1) {
    if (si[i] == '1') {
      pba++;
    } else {
      os++;
      v.pb(pba);
      pba = 0;
    }
  }
  v.pb(pba);
  n = v.size();
  ll dp[310][310][310] = {0}, lla[310][310][310] = {0}, r[310][310][310] = {0};
  // dp[どこまでみた][正の合計][負の合計]
  rep(i, 0, k) { dp[0][i][0] = 1; }
  rep(j, 0, k) {
    rep(l, 0, j) { lla[0][j][l + 1] = (lla[0][j][l] + dp[0][j][l]) % mod; }
  }
  rep(l, 0, k) {
    rep(j, l, k) { r[0][j + 1][l] = (r[0][j][l] + dp[0][j][l]) % mod; }
  }
  rep(i, 1, n - 1) {
    rep(j, 0, k) {
      rep(l, 0, j) {
        dp[i][j][l] = dp[i - 1][j][l];
        dp[i][j][l] =
            (dp[i][j][l] + r[i - 1][j][l] - r[i - 1][l][l] + mod) % mod;
        dp[i][j][l] = (dp[i][j][l] + lla[i - 1][j][l] -
                       lla[i - 1][j][max(0ll, l - v[i])] + mod) %
                      mod;
      }
    }
    rep(j, 0, k) {
      rep(l, 0, j) { lla[i][j][l + 1] = (lla[i][j][l] + dp[i][j][l]) % mod; }
    }
    rep(l, 0, k) {
      rep(j, l, k) { r[i][j + 1][l] = (r[i][j][l] + dp[i][j][l]) % mod; }
    }
  }
  rep(i, 0, k) { ans = (ans + dp[n - 1][i][i]) % mod; }
  cout << ans << endl;
  return 0;
}