alexjercan/bugnet huggingface dataset:
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
using ll = long long;
using Graph = vector<vector<ll>>;

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) { // nのbitと...00001を比較  nが2で割り切れるならtrue
      res = (res * a) % mod;
    }
    a = (a * a) % mod;
    n >>= 1;
  }
  return res;
}

ll modinv(ll a, ll mod) { return modpow(a, mod - 2, mod); }

int main() {
  ll N, S;
  cin >> N >> S;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  ll waru = modinv(2, MOD);

  ll a = modpow(2, N - 1, MOD);

  vector<ll> dp(S + 1, 0);
  for (ll i = 0; i < N; i++) {
    for (ll j = S - A.at(i); j > 0; j--) {
      dp.at(j + A.at(i)) += dp.at(j) * waru % MOD;
      dp.at(j + A.at(i)) %= MOD;
    }
    if (A.at(i) <= S) {
      dp.at(A.at(i)) += a;
      dp.at(A.at(i)) %= MOD;
    }
  }

  cout << dp.at(S) % MOD << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
using ll = long long;
using Graph = vector<vector<int>>;

int main() {
  int N, S;
  cin >> N >> S;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  vector<map<int, ll>> dp(N + 1);
  dp.at(0)[0] = 1;

  for (int i = 0; i < N; i++) {
    for (int j = i; j >= 0; j--) {
      for (auto p : dp.at(j)) {
        if (p.first + A.at(i) <= S) {
          dp.at(j + 1)[p.first + A.at(i)] += dp.at(j)[p.first];
          dp.at(j + 1)[p.first + A.at(i)] %= MOD;
        }
      }
    }
  }

  vector<ll> nijou(N, 1);
  for (int i = 1; i < N; i++) {
    nijou.at(i) = nijou.at(i - 1) * 2;
    nijou.at(i) %= MOD;
  }

  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    for (auto p : dp.at(i)) {
      if (p.first != S) {
        continue;
      }
      ans += p.second * nijou.at(N - i) % MOD;
      ans %= MOD;
    }
  }

  cout << ans << endl;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define FOR(i, a, b) for (auto i = a; i < b; i++)
#define FORD(i, a, b) for (auto i = a - 1; i >= b; i--)
#define FORS(i, a, b, s) for (auto i = a; i < b; i += s)

using namespace std;

typedef long long ll;

#define MOD 998244353

int N, S;
vector<int> a;
ll dp[3001][3001];
ll pow2[3001];
ll solve(int n, int s) {
  if (s == S)
    return pow2[N - n];
  if (s > S)
    return 0;
  if (n >= N)
    return 0;
  if (dp[n][s] != -1)
    return dp[n][s];
  ll ret = (solve(n + 1, s + a[n]) + 2 * solve(n + 1, s)) % MOD;

  dp[n][s] = ret;
  return ret;
}

int main() {
  /* ifstream cin("in.txt"); */

  pow2[0] = 1;
  FOR(i, 1, 3001) pow2[i] = pow2[i - 1] * 2 % MOD;

  memset(dp, -1, sizeof(dp));
  cin >> N >> S;
  a = vector<int>(N);
  FOR(i, 0, N) { cin >> a[i]; }

  cout << solve(0, 0) << endl;
  ;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define FOR(i, a, b) for (auto i = a; i < b; i++)
#define FORD(i, a, b) for (auto i = a - 1; i >= b; i--)
#define FORS(i, a, b, s) for (auto i = a; i < b; i += s)

using namespace std;

typedef long long ll;
#define MOD 998244353
int N, S;
vector<int> a;
ll dp[3001][3001];
int pow2[3001];
ll solve(int n, int cur_sum) {
  if (cur_sum == S)
    return 1;
  if (n >= N || cur_sum > S)
    return 0;
  if (dp[n][cur_sum] != -1)
    return dp[n][cur_sum];
  ll ret = solve(n + 1, cur_sum) + solve(n + 1, cur_sum + a[n]);

  dp[n][cur_sum] = ret;
  return ret;
}

int solve2(int n, int cur_sum, int stack) {
  if (solve(n, cur_sum) == 0)
    return 0;
  if (solve(n, cur_sum) == 1 && cur_sum == S)
    return pow2[N - stack];
  else
    return (solve2(n + 1, cur_sum + a[n], stack + 1) +
            solve2(n + 1, cur_sum, stack)) %
           MOD;
}

int main() {
  /* ifstream cin("in2.txt"); */

  cin >> N >> S;
  a = vector<int>(N);
  FOR(i, 0, N) { cin >> a[i]; }
  pow2[0] = 1;
  FOR(i, 1, 3001) pow2[i] = (pow2[i - 1] * 2) % MOD;

  memset(dp, -1, sizeof(dp));
  cout << solve2(0, 0, 0) << endl;

  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long
#define ff first
#define ss second
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define pb push_back
#define mp make_pair
#define inf 1000000000000000
#define mod 998244353
#define ld long double
#define pll pair<ll, ll>
using namespace std;

ll powa(ll a, ll b) {
  a %= mod;
  if (a == 0)
    return 0;
  ll ans = 1;

  while (b > 0) {
    if (b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

int main() {
  fast;
  ll n, s;
  cin >> n >> s;

  ll a[n + 1];
  for (ll i = 1; i <= n; i++)
    cin >> a[i];

  vector<ll> dp(s + 1, 0);
  dp[0] = 2;
  if (a[1] <= s)
    dp[a[1]] = 1;

  for (ll i = 2; i <= n; i++) {
    vector<ll> tempdp(s + 1, 0);

    for (ll j = 0; j <= s; j++)
      tempdp[j] = (2 * dp[j]) % mod;

    for (ll j = s; j > -1; j--)
      if (j + a[i] <= s)
        tempdp[j + a[i]] = (dp[j] + tempdp[j + a[i]]) % mod;

    for (ll j = 0; j <= s; j++)
      dp[j] = (tempdp[j]) % mod;
  }
  cout << dp[s] << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long
#define ff first
#define ss second
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define pb push_back
#define mp make_pair
#define inf 1000000000000000
#define mod 998244353
#define ld long double
#define pll pair<ll, ll>
using namespace std;

ll powa(ll a, ll b) {
  a %= mod;
  if (a == 0)
    return 0;
  ll ans = 1;

  while (b > 0) {
    if (b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

int main() {
  fast;

  ll n, s;
  cin >> n >> s;

  ll a[n + 1];
  for (ll i = 1; i <= n; i++)
    cin >> a[i];

  vector<ll> dp(s + 1, 0);
  dp[0] = 2;
  dp[a[1]] = 1;

  for (ll i = 2; i <= n; i++) {
    vector<ll> tempdp(s + 1, 0);

    for (ll j = 0; j <= s; j++)
      tempdp[j] = (2 * dp[j]) % mod;

    for (ll j = s; j > -1; j--)
      if (j + a[i] <= s)
        tempdp[j + a[i]] = (dp[j] + tempdp[j + a[i]]) % mod;

    for (ll j = 0; j <= s; j++)
      dp[j] = (tempdp[j]) % mod;
  }
  cout << dp[s] << endl;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

using ll = long long;
using P = pair<int, int>;

const int mod = 998244353;

int main(int, char **) {
  int n, s;
  cin >> n >> s;

  vector<int> a(n);
  rep(i, n) cin >> a[i];

  vector<vector<ll>> dp(n + 1, vector<ll>(s + 1, 0));
  dp[0][0] = 1;
  rep(i, n) rep(j, s + 1) {
    dp[i + 1][j] += dp[i][j] << 1;
    dp[i + 1][j] %= mod;
    if (j + a[i] <= s) {
      dp[i + 1][j + a[i]] += dp[i][j];
      dp[i + 1][j + a[i]] %= mod;
    }
  }

  cout << dp[n][s] << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

using ll = long long;
using P = pair<int, int>;

vector<int> a;
vector<vector<ll>> memo;
const int mod = 998244353;

ll dfs(int n, int s) {
  if (memo[n][s])
    return memo[n][s];

  ll res = 0;
  if (n == 0) {
    if (s == 0)
      res = 1;
  } else {
    res = (res + dfs(n - 1, s) << 1) % mod;
    if (s >= a[n - 1])
      res = (res + dfs(n - 1, s - a[n - 1])) % mod;
  }
  memo[n][s] = res;
  return res;
}

int main(int, char **) {
  int n, s;
  cin >> n >> s;
  a.assign(n, 0);
  memo.assign(n + 1, vector<ll>(s + 1));

  rep(i, n) cin >> a[i];

  cout << dfs(n, s) << endl;

  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

// #pragma GCC optimize("Ofast")

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const int NN = 4e3 + 7;
const int N = 2e5 + 7;
const int M = 22;
const int mod = 998244353;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;
const int B = sqrt(N);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, s;
int a[N];
int p[N];
int d[N];

int pw(int x, int y) {
  if (!y)
    return 1;
  if ((y & 1)) {
    return x * 1ll * pw(x, y - 1) % mod;
  } else {
    int xx = pw(x, y / 2);
    return xx * 1ll * xx % mod;
  }
}

void solve1() {
  cin >> n >> s;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  p[0] = 1;
  for (int i = 1; i < N; i++) {
    p[i] = p[i - 1] * 1ll * 2 % mod;
  }
  d[0] = p[n];
  p[n + 1] = pw(2, mod - 2);
  for (int i = 1; i <= n; i++) {
    for (int j = s; j >= 0; j--) {
      d[j + a[i]] += d[j] * 1ll * p[n + 1] % mod;
      d[j + a[i]] %= mod;
    }
  }
  cout << d[s];
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen( "input.txt" , "r" , stdin );
  // freopen( "output.txt" , "w" , stdout );

  int cghf = 1; // cin >> cghf;
  while (cghf--) {
    solve1();
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

// #pragma GCC optimize("Ofast")

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const int NN = 4e3 + 7;
const int N = 2e5 + 7;
const int M = 22;
const int mod = 998244353;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;
const int B = sqrt(N);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, s;
int a[N];
int p[N];
int d[N];

int pw(int x, int y) {
  if (!y)
    return 1;
  if ((y & 1)) {
    return x * 1ll * pw(x, y - 1) % mod;
  } else {
    int xx = pw(x, y / 2);
    return xx * 1ll * xx % mod;
  }
}

void solve1() {
  cin >> n >> s;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  p[0] = 1;
  for (int i = 1; i < N; i++) {
    p[i] = p[i - 1] * 1ll * 2 % mod;
  }
  d[0] = p[n];
  for (int i = 1; i <= n; i++) {
    for (int j = s; j >= 0; j--) {
      d[j + a[i]] += d[j] * 1ll * pw(2, mod - 2) % mod;
      d[j + a[i]] %= mod;
    }
  }
  cout << d[s];
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen( "input.txt" , "r" , stdin );
  // freopen( "output.txt" , "w" , stdout );

  int cghf = 1; // cin >> cghf;
  while (cghf--) {
    solve1();
  }
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

const ll MOD = 998244353;

ll DP[3030][3030];

// A の部分集合 T、Tの部分集合U で数える
int main() {
  int N, S;
  cin >> N >> S;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];

  DP[0][0] = 1;
  REP(i, N) REP(j, S + 1) {
    // Ai が T に選ばれない場合
    DP[i + 1][j] += DP[i][j];
    // Ai が T には選ばれているけど、Uには選ばれてない場合
    DP[i + 1][j] += DP[i][j];
    DP[i + 1][j] %= MOD;
    // Ai が選ばれた場合
    if (A[i] + j <= S)
      DP[i + 1][j + A[i]] += DP[i][j];
    DP[i + 1][j] %= MOD;
  }
  cout << DP[N][S] << endl;
}


Error: 0

Fixed submission:

#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

const ll MOD = 998244353;

ll DP[3000][3000];

// A の部分集合 T、Tの部分集合U で数える
int main() {
  int N, S;
  cin >> N >> S;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];

  DP[0][0] = 1;
  REP(i, N) REP(j, S + 1) {
    // Ai が T に選ばれない場合
    DP[i + 1][j] += DP[i][j];
    // Ai が T に選ばれていても U には選ばれていない場合
    DP[i + 1][j] += DP[i][j];
    DP[i + 1][j] %= MOD;
    // Ai が選ばれた場合
    if (A[i] + j <= S) {
      DP[i + 1][j + A[i]] += DP[i][j];
      DP[i + 1][j + A[i]] %= MOD;
    }
    DP[i + 1][j] %= MOD;
  }
  cout << DP[N][S] << endl;
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

const ll MOD = 998244353;

ll DP[3001][3001];

// A の部分集合 T、Tの部分集合 U で数える
int main() {
  int N, S;
  cin >> N >> S;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];

  DP[0][0] = 1;
  REP(i, N) REP(j, S + 1) {
    // Ai が T に選ばれない場合
    DP[i + 1][j] += DP[i][j];
    // Ai が T には選ばれているが U には選ばれていない場合
    DP[i + 1][j] += DP[i][j];
    DP[i + 1][j] %= MOD;
    // Ai が選ばれた場合
    if (A[i] + j <= S)
      DP[i + 1][j + A[i]] += DP[i][j];
    DP[i + 1][j] %= MOD;
  }
  cout << DP[N][S] << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

const ll MOD = 998244353;

ll DP[3000][3000];

// A の部分集合 T、Tの部分集合 U で数える
int main() {
  int N, S;
  cin >> N >> S;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];

  DP[0][0] = 1;
  REP(i, N) REP(j, S + 1) {
    // Ai が T に選ばれない場合
    DP[i + 1][j] += DP[i][j];
    // Ai が T には選ばれているが U には選ばれていない場合
    DP[i + 1][j] += DP[i][j];
    DP[i + 1][j] %= MOD;
    // Ai が選ばれた場合
    if (A[i] + j <= S)
      DP[i + 1][j + A[i]] += DP[i][j];
    DP[i + 1][j] %= MOD;
  }
  cout << DP[N][S] << endl;
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

const ll MOD = 998244353;

// あとで S+1 までループを回しているため
ll DP[3001][3001];

// A の部分集合 T、Tの部分集合 U で数える
int main() {
  int N, S;
  cin >> N >> S;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];

  DP[0][0] = 1;
  REP(i, N) REP(j, S + 1) {
    // Ai が T に選ばれない場合
    DP[i + 1][j] += DP[i][j];
    // Ai が T には選ばれているが U には選ばれていない場合
    DP[i + 1][j] += DP[i][j];
    DP[i + 1][j] %= MOD;
    // Ai が選ばれた場合
    if (A[i] + j <= S) {
      DP[i + 1][j + A[i]] += DP[i][j];
      DP[i + 1][j + A[i]] %= MOD;
    }
  }
  cout << DP[N][S] << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

const ll MOD = 998244353;

// あとで S+1 までループを回しているため
ll DP[3000][3001];

// A の部分集合 T、Tの部分集合 U で数える
int main() {
  int N, S;
  cin >> N >> S;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];

  DP[0][0] = 1;
  REP(i, N) REP(j, S + 1) {
    // Ai が T に選ばれない場合
    DP[i + 1][j] += DP[i][j];
    // Ai が T には選ばれているが U には選ばれていない場合
    DP[i + 1][j] += DP[i][j];
    DP[i + 1][j] %= MOD;
    // Ai が選ばれた場合
    if (A[i] + j <= S) {
      DP[i + 1][j + A[i]] += DP[i][j];
      DP[i + 1][j + A[i]] %= MOD;
    }
  }
  cout << DP[N][S] << endl;
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
const int mod = 998244353;

using namespace std;

int s, n;

void knapsackSubset() // coeff x^s du polynome Pi(2+x^ai)
{
  scanf("%d%d", &n, &s);
  int x;
  vector<long long> coeff(3000, 0);
  cin >> x;
  coeff[0] = 2, coeff[x] = 1;
  for (int i = 1; i < n; i++) {
    scanf("%d", &x);
    vector<long long> oldCo =
        coeff; // ancient coordonnes, (ne pas oublier qu'on mulitplie par 2, on
               // doit se rappeler des ancierts coo, quitte a diviser par 2
               // aussi)
    for (int j = 0; j <= s; j++) {
      coeff[j] = (2 * coeff[j]) % mod;
      if (j >= x)
        coeff[j] += oldCo[j - x];
      coeff[j] %= mod;
    }
  }
  cout << coeff[s] << endl;
}

int main() {
#ifdef ME
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  knapsackSubset();
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
const int mod = 998244353;

using namespace std;

long long s, n;

void knapsackSubset() // coeff x^s du polynome Pi(2+x^ai)
{
  scanf("%lld%lld", &n, &s);
  long long x;
  vector<long long> coeff(s + 1, 0);
  cin >> x;
  coeff[0] = 2, coeff[x] = 1;
  for (int i = 1; i < n; i++) {
    scanf("%lld", &x);
    vector<long long> oldCo =
        coeff; // ancient coordonnes, (ne pas oublier qu'on mulitplie par 2, on
               // doit se rappeler des ancierts coo, quitte a diviser par 2
               // aussi)
    for (int j = 0; j <= s; j++) {
      coeff[j] = (2 * coeff[j]) % mod;
      if (j >= x)
        coeff[j] += oldCo[j - x];
      coeff[j] %= mod;
    }
  }
  cout << coeff[s] << endl;
}

int main() {
#ifdef ME
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  knapsackSubset();
  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const long long N = 3e3 + 5, M = 998244353, OO = 0x3f3f3f3f;
typedef long long ll;
#define FIO                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
const double Pii = 3.14159265359;
ll n, m;
ll mem[N][N];
ll a[N];
ll solve(int idx, int su) {
  if (idx == n) {
    if (su == m)
      return 1;
    return 0;
  }
  if (mem[idx][su] != -1)
    return mem[idx][su];
  ll op1 = 0, op2 = 0;
  if (su + a[idx] <= m)
    op1 = solve(idx + 1, su + a[idx]);
  op2 = (solve(idx + 1, su) * 2);
  return mem[idx][su] = (op1 + (op2 % M)) % M;
}

int main() {
  FIO cin >> n >> m;
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  memset(mem, -1, sizeof mem);
  ll ans = solve(0, 0);
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const long long N = 1e3 + 5, M = 998244353, OO = 0x3f3f3f3f;
typedef long long ll;
#define FIO                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
const double Pii = 3.14159265359;
ll n, m;
ll mem[N][N];
ll a[N];
ll solve(int idx, int su) {
  if (idx == n) {
    if (su == m)
      return 1;
    return 0;
  }
  if (mem[idx][su] != -1)
    return mem[idx][su];
  ll op1 = 0, op2 = 0;
  if (su + a[idx] <= m)
    op1 = solve(idx + 1, su + a[idx]);
  op2 = (solve(idx + 1, su) * 2);
  return mem[idx][su] = (op1 + (op2 % M)) % M;
}

int main() {
  FIO cin >> n >> m;
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  memset(mem, -1, sizeof mem);
  ll ans = solve(0, 0);
  cout << ans << endl;
  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

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

#define FOR(s, i, n) for (int i = s; i n; i++)
typedef long long ll;
const int INF = 1e9;

// 1000 mb = 1e9 b = 2.5e8 intergers

const int MOD = 998244353;
ll dp[3005][7000] = {{0}};  // ans up to i and n = i
ll dp2[3005][7000] = {{0}}; // solCnt up to i
ll binPow(ll x, ll k) {
  ll ans = 1;
  while (k > 0) {
    if (k % 2 == 0) {
      x = (x * x) % MOD;
      k /= 2;
    } else {
      ans = (ans * x) % MOD;
      k--;
    }
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  int n, s;
  cin >> n >> s;
  vector<int> nums(n);
  for (int i = 0; i < n; i++) {
    cin >> nums[i];
  }
  for (int i = 0; i < n; i++) {
    dp[i][0] = binPow(2, i);
    // dp2[i][0] = 1;
    for (int j = 0; j <= 3000; j++) {
      dp[i + 1][j] += dp[i][j] * 2;
      dp[i + 1][j] %= MOD;
      dp[i + 1][j + nums[i]] += dp[i][j];
      dp[i + 1][j + nums[i]] %= MOD;
      // dp2[i+1][j] += dp2[i][j];
      // dp2[i+1][j+nums[i]] += dp2[i][j];
    }
  }

  // for (int i = 0; i <= n; i++){
  // 	for (int j = 0; j <= 10; j++){
  // 		cout<<dp[i][j]<<' ';
  // 	}
  // 	cout<<'\\n';
  // }
  cout << dp[n][s] << '\\n';
  return 0;
}

Error: -11

Fixed submission:

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

#define FOR(s, i, n) for (int i = s; i n; i++)
typedef long long ll;
const int INF = 1e9;

// 1000 mb = 1e9 b = 2.5e8 intergers

const int MOD = 998244353;
ll dp[3000][7000] = {{0}};  // ans up to i and n = i
ll dp2[3000][7000] = {{0}}; // solCnt up to i
ll binPow(ll x, ll k) {
  ll ans = 1;
  while (k > 0) {
    if (k % 2 == 0) {
      x = (x * x) % MOD;
      k /= 2;
    } else {
      ans = (ans * x) % MOD;
      k--;
    }
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  int n, s;
  cin >> n >> s;
  vector<int> nums(n);
  for (int i = 0; i < n; i++) {
    cin >> nums[i];
  }
  for (int i = 0; i < n; i++) {
    dp[i][0] = binPow(2, i);
    // dp2[i][0] = 1;
    for (int j = 0; j <= 3000; j++) {
      dp[i + 1][j] += dp[i][j] * 2;
      dp[i + 1][j] %= MOD;
      dp[i + 1][j + nums[i]] += dp[i][j];
      dp[i + 1][j + nums[i]] %= MOD;
      // dp2[i+1][j] += dp2[i][j];
      // dp2[i+1][j+nums[i]] += dp2[i][j];
    }
  }

  // for (int i = 0; i <= n; i++){
  // 	for (int j = 0; j <= 10; j++){
  // 		cout<<dp[i][j]<<' ';
  // 	}
  // 	cout<<'\\n';
  // }
  cout << dp[n][s] << '\\n';
  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

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

const int MOD = 998244353;
const int MAX_N = 3005;
int N, S;
int A[MAX_N];

ll dp[MAX_N][MAX_N]; // len, sum

ll powmod(ll x, int y) {
  ll res = 1;
  while (y) {
    if (y & 1)
      (res *= x) %= MOD;
    (x *= x) %= MOD;
    y >>= 1;
  }
  return res;
}

void solve() {
  dp[0][0] = powmod(2, N);
  for (int i = 0; i < N; ++i)
    for (int j = 0; j <= S; ++j) {
      (dp[i + 1][j] += dp[i][j]) %= MOD;
      if (j + A[i] <= S)
        (dp[i + 1][j + A[i]] += dp[i][j] * powmod(2, MOD - 2) % MOD) %= MOD;
    }
  cout << dp[N][S];
}

int main() {
  cin >> N >> S;
  for (int i = 0; i < N; ++i)
    cin >> A[i];
  solve();
  return 0;
}

Error: WA

Fixed submission:

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

const int MOD = 998244353;
const int MAX_N = 305;
int N, S;
int A[MAX_N];

ll dp[MAX_N][MAX_N]; // len, sum

ll powmod(ll x, int y) {
  ll res = 1;
  while (y) {
    if (y & 1)
      (res *= x) %= MOD;
    (x *= x) %= MOD;
    y >>= 1;
  }
  return res;
}

void solve() {
  dp[0][0] = powmod(2, N);
  for (int i = 0; i < N; ++i)
    for (int j = 0; j <= S; ++j) {
      (dp[i + 1][j] += dp[i][j]) %= MOD;
      if (j + A[i] <= S)
        (dp[i + 1][j + A[i]] += dp[i][j] * powmod(2, MOD - 2) % MOD) %= MOD;
    }
  cout << dp[N][S];
}

int main() {
  cin >> N >> S;
  for (int i = 0; i < N; ++i)
    cin >> A[i];
  solve();
  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define per(i, n) for (int i = (n)-1; i >= 0; --i)
#define rng(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
const int mod = 998244353;

int main() {
  ll n, s;
  cin >> n >> s;
  vl a(n);
  rep(i, n) cin >> a[i];
  vl dp(6060);
  dp[0] = 1;
  rep(i, n) {
    vl ndp(6060);
    rep(j, 3030) {
      (ndp[j] += dp[j] * 2) %= mod;
      (ndp[j + a[i]] += dp[j]) %= mod;
    }
    dp = ndp;
  }
  cout << dp[s] << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define per(i, n) for (int i = (n)-1; i >= 0; --i)
#define rng(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
const int mod = 998244353;

int main() {
  ll n, s;
  cin >> n >> s;
  vl a(n);
  rep(i, n) cin >> a[i];
  vl dp(6060);
  dp[0] = 1;
  rep(i, n) {
    vl ndp(6060);
    rep(j, 6060) {
      (ndp[j] += dp[j] * 2) %= mod;
      (ndp[j + a[i]] += dp[j]) %= mod;
    }
    dp = ndp;
  }
  cout << dp[s] << endl;
  return 0;
}