alexjercan/bugnet huggingface dataset:
Problem p02635 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
void add(int &x, int y) { x = (x + y) % mod; }
int n, k, f[305][305][305], cnt[505], suf[505];
char s[505];
signed main() {
  scanf("%s%d", (s + 1), &k);
  n = strlen(s + 1);
  k = min(n, k);
  int res = 0, tot = 0;
  // cout<<n<<" "<<k<<endl;
  for (int i = 1; i <= n; ++i)
    if (s[i] == '0')
      cnt[++tot] = res, res = 0;
    else
      ++res;
  if (res)
    cnt[++tot] = res;
  for (int i = tot; i >= 1; --i)
    suf[i] = suf[i + 1] + cnt[i];
  f[0][0][0] = 1;
  for (int i = 1; i <= tot; ++i)
    for (int one = 0; one <= n; ++one)
      for (int st = 0; st <= k; ++st)
        if (f[i - 1][one][st]) {
          for (int v = 0; v <= cnt[i]; ++v) {
            int tmp = one - (cnt[i] - v);
            if (tmp >= 0 && tmp <= suf[i + 1]) {
              // if(tmp>300) return puts("-1"),int(0);
              add(f[i][tmp][st], f[i - 1][one][st]);
            }
          }
          for (int v = cnt[i] + 1; one - (cnt[i] - v) <= suf[i + 1]; ++v) {
            int tmp = one - (cnt[i] - v);
            if (tmp >= 0 && tmp <= suf[i + 1]) {
              // if(tmp>300 || st+v-cnt[i]>300) return puts("-1"),int(0);
              add(f[i][tmp][st + v - cnt[i]], f[i - 1][one][st]);
            }
          }
        }
  int ans = 0;
  for (int st = 0; st <= k; ++st)
    add(ans, f[tot][0][st]);
  cout << ans;
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int add(int &x, int y) { x = (x + y) % mod; }
int n, k, f[305][305][305], cnt[505], suf[505];
char s[505];
signed main() {
  scanf("%s%d", (s + 1), &k);
  n = strlen(s + 1);
  k = min(n, k);
  int res = 0, tot = 0;
  for (int i = 1; i <= n; ++i)
    if (s[i] == '0')
      cnt[++tot] = res, res = 0;
    else
      ++res;
  if (res)
    cnt[++tot] = res;
  for (int i = tot; i >= 1; --i)
    suf[i] = suf[i + 1] + cnt[i];
  f[0][0][0] = 1;
  for (int i = 1; i <= tot; ++i)
    for (int one = 0; one <= n; ++one)
      for (int st = 0; st <= k; ++st)
        if (f[i - 1][one][st]) {
          for (int v = 0; v <= cnt[i]; ++v) {
            int tmp = one - (cnt[i] - v);
            if (tmp >= 0 && tmp <= suf[i + 1])
              add(f[i][tmp][st], f[i - 1][one][st]);
          }
          for (int v = cnt[i] + 1; one - (cnt[i] - v) <= suf[i + 1]; ++v) {
            int tmp = one - (cnt[i] - v);
            if (tmp >= 0 && tmp <= suf[i + 1])
              add(f[i][tmp][st + v - cnt[i]], f[i - 1][one][st]);
          }
        }
  int ans = 0;
  for (int st = 0; st <= k; ++st)
    add(ans, f[tot][0][st]);
  cout << ans;
  return 0;
}
Problem p02635 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int d[333][666][666];
vector<int> u;
int p = 998244353;
int f(int i, int v, int w) {
  if (!i)
    return v ? 0 : 1;
  if (v > w)
    return 0;
  if (d[i][v][w] >= 0)
    return d[i][v][w];
  d[i][v][w] = 0;
  for (int j = max(-u[i - 1], -w); j <= v; j++)
    (d[i][v][w] += f(i - 1, v - j, w - abs(j))) %= p;
  return d[i][v][w];
}
int main() {
  string s;
  int k;
  cin >> s >> k;
  k = min(k, 300);
  k += k;
  for (s += '0';;) {
    auto i = s.find('0');
    if (i == -1)
      break;
    s = s.substr(i + 1);
    u.push_back(i);
  }
  for (int i = 0; i < 333; i++)
    for (int j = 0; j <= k; j++)
      for (int w = 0; w <= k; w++)
        d[i][j][w] = -1;
  cout << f(u.size(), 0, k) << endl;
  return 0;
}


Error: MLE

Fixed submission:

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

long d[333][666][666];
vector<int> u;
int p = 998244353;
int f(int i, int v, int w) {
  if (!i)
    return v ? 0 : 1;
  if (v > w)
    return 0;
  if (d[i][v][w] >= 0)
    return d[i][v][w];
  d[i][v][w] = 0;
  for (int j = max(-u[i - 1], -w); j <= v; j++)
    (d[i][v][w] += f(i - 1, v - j, w - abs(j))) %= p;
  return d[i][v][w];
}
int main() {
  string s;
  int k;
  cin >> s >> k;
  k = min(k, 300);
  k += k;
  for (s += '0';;) {
    auto i = s.find('0');
    if (i == -1)
      break;
    s = s.substr(i + 1);
    u.push_back(i);
  }
  for (int i = 0; i < 333; i++)
    for (int j = 0; j <= k; j++)
      for (int w = 0; w <= k; w++)
        d[i][j][w] = -1;
  cout << f(u.size(), 0, k) << endl;
  return 0;
}
Problem p02635 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
// mt19937
// mrand(chrono::high_resolution_clock::now().time_since_epoch().count()); int
// rnd(int x) { return mrand()%x;}
typedef long long ll;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
char s[500];
ll dp[500][500][500];
ll k;
vector<ll> v;
ll suf[400];
int len;
const ll md = 998244353;
ll dfs(ll pos, ll lim, ll res) {
  if (pos == len) {
    if (lim == 0)
      return 1;
    else
      return 0;
  }
  if (dp[pos][lim][res] != -1)
    return dp[pos][lim][res];
  ll ret = 0;
  for (int i = max(v[pos] - lim, 0ll);
       i - v[pos] + lim <= suf[pos] && i - v[pos] <= res; i++) {
    ret =
        (ret + dfs(pos + 1, lim + i - v[pos], res - max(0ll, i - v[pos]))) % md;
  }
  dp[pos][lim][res] = ret;
  return ret;
}
int main() {
  memset(dp, -1, sizeof(dp));
  scanf("%s%lld", s + 1, &k);
  k = min(k, 300ll);
  ll cnt = 0;
  for (int i = 1; s[i]; i++) {
    if (s[i] == '0') {
      v.push_back(cnt);
      cnt = 0;
    } else {
      cnt++;
    }
  }
  v.push_back(cnt);
  len = (int)v.size();
  suf[len] = 0;
  for (int i = len - 1; i >= 0; i--) {
    suf[i] = suf[i + 1] + v[i];
  }
  ll ans = dfs(0, 0, min(k, 300ll));
  printf("%lld\\n", ans);
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
// mt19937
// mrand(chrono::high_resolution_clock::now().time_since_epoch().count()); int
// rnd(int x) { return mrand()%x;}
typedef long long ll;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
char s[500];
ll dp[500][500][500];
ll k;
vector<ll> v;
int len;
const ll md = 998244353;
ll dfs(ll pos, ll lim, ll res) {
  if (pos == len) {
    if (lim == 0)
      return 1;
    else
      return 0;
  }
  if (dp[pos][lim][res] != -1)
    return dp[pos][lim][res];
  ll ret = 0;
  for (int i = max(v[pos] - lim, 0ll);
       i - v[pos] + lim <= 300 && i - v[pos] <= res; i++) {
    ret =
        (ret + dfs(pos + 1, lim + i - v[pos], res - max(0ll, i - v[pos]))) % md;
  }
  dp[pos][lim][res] = ret;
  return ret;
}
int main() {
  memset(dp, -1, sizeof(dp));
  scanf("%s%lld", s + 1, &k);
  ll cnt = 0;
  for (int i = 1; s[i]; i++) {
    if (s[i] == '0') {
      v.push_back(cnt);
      cnt = 0;
    } else {
      cnt++;
    }
  }
  v.push_back(cnt);
  len = (int)v.size();
  ll ans = dfs(0, 0, min(k, 300ll));
  printf("%lld\\n", ans);
  return 0;
}
Problem p02635 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;

const int N = 3e2 + 5;

int n, a[N], dp[N][N][N], pref[N];
const int M = 998244353;

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string S;
  int k;
  cin >> S >> k;
  int sz = S.size();
  k = min(k, sz);
  int cur = 0;
  for (int i = 0; i < S.size(); i++)
    if (S[i] == '1')
      cur++;
    else
      n++, a[n] = cur, cur = 0;
  n++;
  a[n] = cur;
  for (int i = 1; i <= n; i++)
    pref[i] = pref[i - 1] + a[i];
  dp[0][0][0] = 1;
  for (int i = 1; i <= n; i++)
    for (int s = pref[i]; s <= pref[n]; s++)
      for (int j = 0; j <= k; j++) {
        for (int q = max(1ll, a[i] - s); q <= a[i]; q++)
          // if (s >= a[i] - q)
          dp[i][s][j] += dp[i - 1][s - (a[i] - q)][j], dp[i][s][j] %= M;
        for (int q = 0; q <= min(j, s - a[i]); q++)
          // if (s >= a[i] + q)
          dp[i][s][j] += dp[i - 1][s - (a[i] + q)][j - q], dp[i][s][j] %= M;
        // cout << i << ' ' << s << ' ' << j << ' ' << dp[i][s][j] << endl;
      }
  int ans = 0;
  for (int j = 0; j <= k; j++)
    ans += dp[n][pref[n]][j], ans %= M;
  cout << ans;
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;

const int N = 3e2 + 5;

int n, a[N], dp[N][N][N], pref[N];
const int M = 998244353;

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string S;
  int k;
  cin >> S >> k;
  int cur = 0;
  for (int i = 0; i < S.size(); i++)
    if (S[i] == '1')
      cur++;
    else
      n++, a[n] = cur, cur = 0;
  n++;
  a[n] = cur;
  for (int i = 1; i <= n; i++)
    pref[i] = pref[i - 1] + a[i];
  dp[0][0][0] = 1;
  for (int i = 1; i <= n; i++)
    for (int s = pref[i]; s <= pref[n]; s++)
      for (int j = 0; j <= k; j++) {
        for (int q = max(1ll, a[i] - s); q <= a[i]; q++)
          // if (s >= a[i] - q)
          dp[i][s][j] += dp[i - 1][s - (a[i] - q)][j], dp[i][s][j] %= M;
        for (int q = 0; q <= min(j, s - a[i]); q++)
          // if (s >= a[i] + q)
          dp[i][s][j] += dp[i - 1][s - (a[i] + q)][j - q], dp[i][s][j] %= M;
        // cout << i << ' ' << s << ' ' << j << ' ' << dp[i][s][j] << endl;
      }
  int ans = 0;
  for (int j = 0; j <= k; j++)
    ans += dp[n][pref[n]][j], ans %= M;
  cout << ans;
  return 0;
}
Problem p02635 (C++) — buggy submission, verdict: Runtime Error

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

const int maxN = 305, mod = 998244353;

int n, m;
int f[2][maxN + 1][maxN + 1];
int a[maxN + 1], cnt;
char s[maxN + 1];

inline void update(int &x, int y) { x = x + y >= mod ? x + y - mod : x + y; }

int main() {
  scanf("%s %d", s + 1, &m);
  n = strlen(s + 1);
  m = min(m, n);

  int l = 1;
  while (l <= n) {
    int r = l;
    while (r <= n && s[r] == '1')
      r++;
    a[++cnt] = r - l;
    l = r + 1;
  }

  int now = 0;
  f[now][0][0] = 1;
  for (int i = cnt; i >= 1; i--) {
    now ^= 1;
    memset(f[now], 0, sizeof(f[now]));
    for (int j = 0; j <= m; j++)
      for (int k = 0; k <= j; k++) {
        if (!f[now ^ 1][j][k])
          continue;
        int res = f[now ^ 1][j][k];
        for (int t = 0; t <= a[i]; t++)
          update(f[now][j + t][k + t], res);
        for (int t = 1; t <= k; t++)
          update(f[now][j][k - t], res);
      }
  }

  int ans = 0;
  for (int i = 0; i <= m; i++)
    update(ans, f[now][i][0]);

  printf("%d\\n", ans);
  return 0;
}


Error: 0

Fixed submission:

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

const int maxN = 305, mod = 998244353;

int n, m;
int f[2][maxN + 1][maxN + 1];
int a[maxN + 1], cnt;
char s[maxN + 1];

inline void update(int &x, int y) { x = x + y >= mod ? x + y - mod : x + y; }

int main() {
  scanf("%s %d", s + 1, &m);
  n = strlen(s + 1);

  int l = 1;
  while (l <= n) {
    int r = l;
    while (r <= n && s[r] == '1')
      r++;
    a[++cnt] = r - l;
    l = r + 1;
  }

  int now = 0;
  f[now][0][0] = 1;
  for (int i = cnt; i >= 1; i--) {
    now ^= 1;
    memset(f[now], 0, sizeof(f[now]));
    for (int j = 0; j <= m; j++)
      for (int k = 0; k <= j; k++) {
        if (!f[now ^ 1][j][k])
          continue;
        int res = f[now ^ 1][j][k];
        for (int t = 0; t <= a[i]; t++)
          update(f[now][j + t][k + t], res);
        for (int t = 1; t <= k; t++)
          update(f[now][j][k - t], res);
      }
  }

  int ans = 0;
  for (int i = 0; i <= m; i++)
    update(ans, f[now][i][0]);

  printf("%d\\n", ans);
  return 0;
}
Problem p02635 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pi;
typedef long long ll;

const ll mod = 998244353;

string s;
ll K, dp[305][305][305]; // groups, moves, carry
ll N, sz[305];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> s >> K;

  int gn = 1, gz = 0;
  N = s.size();
  K = min(K, N);
  reverse(s.begin(), s.end());

  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == '0') {
      sz[gn] = gz;
      gz = 0;
      gn++;
    } else
      gz++;
  }
  sz[gn] = gz;
  /*
  for (int i = 1; i <= gn; ++i){
          cout << sz[i] << ' ';
  }
  cout << '\\n';
  */
  dp[0][0][0] = 1;
  for (ll i = 1; i <= gn; ++i) {
    for (ll k = 0; k <= K; ++k) {
      for (ll c = 0; c <= k; ++c) {
        for (ll l = 0; (c + l) <= k; ++l) {
          dp[i][k][c] += dp[i - 1][k][c + l];
          dp[i][k][c] %= mod;
        }
        for (ll l = 1; l <= min(min(sz[i], k), c); ++l) {
          dp[i][k][c] += dp[i - 1][k - l][c - l];
          dp[i][k][c] %= mod;
        }
        // cout << i << ' ' << k << ' ' << c << ' ' << dp[i][k][c] << '\\n';
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i <= K; ++i) {
    ans += dp[gn][i][0];
    ans %= mod;
  }
  cout << ans << '\\n';
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pi;
typedef long long ll;

const ll mod = 998244353;

string s;
ll K, dp[305][305][305]; // groups, moves, carry
ll N, sz[305];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> s >> K;

  int gn = 1, gz = 0;
  N = s.size();
  K = min(K, N);
  reverse(s.begin(), s.end());

  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == '0') {
      sz[gn] = gz;
      gz = 0;
      gn++;
    } else
      gz++;
  }
  sz[gn] = gz;
  /*
  for (int i = 1; i <= gn; ++i){
          cout << sz[i] << ' ';
  }
  cout << '\\n';
  */
  dp[0][0][0] = 1;
  for (ll i = 1; i <= gn; ++i) {
    for (ll k = 0; k <= K; ++k) {
      for (ll c = 0; c <= k; ++c) {
        for (ll l = 0; (c + l) <= N; ++l) {
          dp[i][k][c] += dp[i - 1][k][c + l];
          dp[i][k][c] %= mod;
        }
        for (ll l = 1; l <= min(min(sz[i], k), c); ++l) {
          dp[i][k][c] += dp[i - 1][k - l][c - l];
          dp[i][k][c] %= mod;
        }
        // cout << i << ' ' << k << ' ' << c << ' ' << dp[i][k][c] << '\\n';
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i <= K; ++i) {
    ans += dp[gn][i][0];
    ans %= mod;
  }
  cout << ans << '\\n';
}
Problem p02635 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ff first
#define ss second
#define pii pair<int, int>
#define pb emplace_back
#define pf emplace_front
#define mp make_pair
#define ld long double
#define all(x) x.begin(), x.end()
#define uniq(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())

const int maxn = 1009;
int dp[maxn][maxn];
int dp1[maxn][maxn];
int dp2[maxn][maxn];
int n, k;
int mod = 998244353;

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s >> k;
  n = s.size();
  int len = 0;
  dp[0][0] = 1;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '1') {
      len++;
      continue;
    }
    for (int e = 0; e <= n; e++)
      for (int j = n; j >= 0; j--)
        dp1[e][j] = (dp1[e][j + 1] + dp[e][j]) % mod;
    for (int e = 0; e <= n; e++)
      for (int j = 0; j <= n; j++) {
        dp2[e][j] = ((j ? dp2[e][j - 1] : 0) + dp[e + j][j]) % mod;
        if (j - len - 1 >= 0 && e + (j - len - 1) <= n)
          dp2[e][j] =
              (dp2[e][j] - dp[e + (j - len - 1)][j - len - 1] + mod) % mod;
      }
    for (int e = 0; e <= n; e++)
      for (int j = 0; j <= n && j <= e; j++) {
        dp[e][j] = (dp1[e][j] + dp2[e - j][j] - dp[e][j] + mod) % mod;
        //            cout << i << " " << e << " " << j << " " << dp[e][j] <<
        //            "\\n";
      }
    len = 0;
  }
  int ans = 0;
  for (int e = 0; e <= k && e <= n; e++)
    for (int j = 0; j <= n; j++)
      ans = (ans + dp[e][j]) % mod;
  cout << ans;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ff first
#define ss second
#define pii pair<int, int>
#define pb emplace_back
#define pf emplace_front
#define mp make_pair
#define ld long double
#define all(x) x.begin(), x.end()
#define uniq(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())

const int maxn = 1009;
int dp[maxn][maxn];
int dp1[maxn][maxn];
int dp2[maxn][maxn];
int n, k;
int mod = 998244353;

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s >> k;
  n = s.size();
  int len = 0;
  dp[0][0] = 1;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '1') {
      len++;
      continue;
    }
    for (int e = 0; e <= n; e++)
      for (int j = n; j >= 0; j--)
        dp1[e][j] = (dp1[e][j + 1] + dp[e][j]) % mod;
    for (int e = 0; e <= 2 * n; e++)
      for (int j = 0; j <= n; j++) {
        dp2[e][j] = ((j ? dp2[e][j - 1] : 0) + dp[e + j][j]) % mod;
        if (j - len - 1 >= 0 && e + (j - len - 1) <= 2 * n)
          dp2[e][j] =
              (dp2[e][j] - dp[e + (j - len - 1)][j - len - 1] + mod) % mod;
      }
    for (int e = 0; e <= n; e++)
      for (int j = 0; j <= n; j++) {
        dp[e][j] = (dp1[e][j] + dp2[e - j][j] - dp[e][j] + mod) % mod;
        //            cout << i << " " << e << " " << j << " " << dp[e][j] <<
        //            "\\n";
      }
    len = 0;
  }
  int ans = 0;
  for (int e = 0; e <= k && e <= n; e++)
    for (int j = 0; j <= n; j++)
      ans = (ans + dp[e][j]) % mod;
  cout << ans;
}
Problem p02635 (C++) — buggy submission, verdict: Runtime Error

#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 310, mod = 998244353;
char s[N];
int K, ct, n, m;
int w[N];
ll sum, f[N][N][N];
void pls(ll &x, ll y) {
  x += y;
  x >= mod ? x -= mod : 0;
}
int main() {
  //	freopen("a.in","r",stdin);
  scanf("%s%d", s + 1, &K);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++)
    if (s[i] == '0')
      m++, w[m] = ct, ct = 0;
    else
      ct++;
  m++;
  w[m] = ct;
  f[m + 1][0][0] = 1;
  for (int i = m; i; i--) {
    sum = min(sum, (ll)K);
    for (int j = 0; j <= sum; j++)
      for (int k = j; k <= sum; k++)
        for (int c = 0; c <= j + w[i]; c++) {
          if (c < w[i])
            pls(f[i][j + w[i] - c][k + w[i] - c], f[i + 1][j][k]);
          else
            pls(f[i][j + w[i] - c][k], f[i + 1][j][k]);
        }
    sum += w[i];
  }
  K = min(K, n);
  sum = 0;
  for (int i = 0; i <= K; i++)
    pls(sum, f[1][0][i]);
  cout << sum;
}

Error: -11

Fixed submission:

#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 310, mod = 998244353;
char s[N];
int K, ct, n, m;
int w[N];
ll sum, f[N][N][N];
void pls(ll &x, ll y) {
  x += y;
  x >= mod ? x -= mod : 0;
}
int main() {
  //	freopen("a.in","r",stdin);
  scanf("%s%d", s + 1, &K);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++)
    if (s[i] == '0')
      m++, w[m] = ct, ct = 0;
    else
      ct++;
  m++;
  w[m] = ct;
  f[m + 1][0][0] = 1;
  for (int i = m; i; i--) {
    sum = min(sum, (ll)K);
    for (int j = 0; j <= sum; j++)
      for (int k = j; k <= sum; k++)
        for (int c = 0; c <= j + w[i]; c++) {
          if (c < w[i])
            pls(f[i][j + w[i] - c][k + w[i] - c], f[i + 1][j][k]);
          else
            pls(f[i][j + w[i] - c][k], f[i + 1][j][k]);
        }
    sum += w[i];
  }
  sum = 0;
  for (int i = 0; i <= K; i++)
    pls(sum, f[1][0][i]);
  cout << sum;
}
Problem p02635 (C++) — buggy submission, verdict: Runtime Error

#pragma GCC optimize("O2")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
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 ll mod = 998244353;

ll dp[310][310];

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

  string S;
  int K;
  int k = 0;
  int A[301] = {};

  cin >> S >> K;
  rep(i, S.size()) {
    if (S[i] == '0')
      k++;
    else {
      A[k]++;
    }
  }

  int kosuu = 0;
  dp[0][0] = 1;
  for (int i = k; i >= 0; i--) {
    for (int j = kosuu; j >= 0; j--) {
      ll tmp = 0;
      for (int k = kosuu; k >= 0; k--) {
        dp[j][k] %= mod;
        tmp += dp[j][k];
        rep1(p, A[i]) dp[j + p][k + p] += dp[j][k];
        dp[j][k] = tmp;
      }
    }
    kosuu += A[i];
  }

  ll kotae = 0;
  rep(i, min(K, kosuu) + 1) { kotae += dp[i][0] % mod; }
  co(kotae % mod);

  Would you please return 0;
}


Error: 0

Fixed submission:

#pragma GCC optimize("O2")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
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 ll mod = 998244353;

ll dp[310][310];

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

  string S;
  int K;

  int kosuu = 0;
  int k = 0;
  int A[301] = {};

  cin >> S >> K;
  rep(i, S.size()) {
    if (S[i] == '0')
      k++;
    else {
      A[k]++;
      kosuu++;
    }
  }

  dp[0][0] = 1;
  for (int i = k; i >= 0; i--) {
    for (int j = kosuu; j >= 0; j--) {
      ll tmp = 0;
      for (int k = kosuu; k >= 0; k--) {
        dp[j][k] %= mod;
        tmp += dp[j][k];
        rep1(p, A[i]) dp[j + p][k + p] += dp[j][k];
        dp[j][k] = tmp;
      }
    }
  }

  ll kotae = 0;
  rep(i, min(K, kosuu) + 1) { kotae += dp[i][0] % mod; }
  co(kotae % mod);

  Would you please return 0;
}