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

#include <algorithm>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
long long mod = 998244353;
int n;
int a[3000];
int s;
long long dp[3001][3001] = {};
int main() {
  cin >> n >> s;
  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    for (int j = s; j >= 0; j--) {
      (dp[i + 1][j] += dp[i][j]) %= mod;
      if (j + a[i] <= s) {
        (dp[i + 1][j + a[i]] += dp[i][j]) %= mod;
      }
      (dp[i + 1][j] *= 2) %= mod;
    }
  }
  cout << dp[n][s] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
long long mod = 998244353;
int n;
int a[3000];
int s;
long long dp[3001][3001] = {};
int main() {
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  //
  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = i; j >= 0; j--) {
      for (int k = 0; k <= s - a[i]; k++) {
        (dp[j + 1][k + a[i]] += dp[j][k]) %= mod;
      }
    }
  }
  long long beki[3001];
  beki[0] = 1;
  for (int i = 1; i <= n; i++) {
    (beki[i] = beki[i - 1] * 2) %= mod;
  }
  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    //		cout<<i<<" "<<dp[i][s]<<endl;
    (ans += dp[i][s] * beki[n - i]) %= mod;
  }
  cout << ans << endl;
  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;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, S;
  cin >> N >> S;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);

  vector<vector<ll>> dp(N, vector<ll>(S + 1, 0));
  dp[0][0] = 2;
  if (A[0] <= S)
    dp[0][A[0]] = 1;

  for (int i = 1; i < N; i++) {
    for (int j = 0; j < S + 1; j++) {
      dp[i][j] += 2 * dp[i - 1][j];
      dp[i][j] %= mod;
      if (j + A[i] <= S) {
        dp[i][j + A[i]] += dp[i - 1][j];
        dp[i][j + A[i]] %= mod;
      }
    }
  }
  cout << dp[N - 1][S] << endl;

  return 0;
}


Error: 0

Fixed submission:

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

const int mod = 998244353;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, S;
  cin >> N >> S;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);

  vector<vector<int>> dp(N, vector<int>(S + 1, 0));
  dp[0][0] = 2;
  dp[0][A[0]] = 1;

  for (int i = 1; i < N; i++) {
    for (int j = 0; j < S + 1; j++) {
      dp[i][j] += 2 * dp[i - 1][j];
      dp[i][j] %= mod;
      if (j + A[i] <= S) {
        dp[i][j + A[i]] += dp[i - 1][j];
        dp[i][j + A[i]] %= mod;
      }
    }
  }
  cout << dp[N - 1][S] << endl;

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

#pragma GCC optimize("O3")
#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 int mod = 998244353;
const int IMAX = 100000;
constexpr ll modpow(ll A, ll B) {
  ll kotae = 1;
  while (B > 0) {
    if (B & 1)
      kotae = kotae * A % mod;
    A = A * A % mod;
    B >>= 1;
  }
  return kotae;
}

ll dp[3001];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, S;
  cin >> N >> S;

  int A[3000];
  rep(i, N) cin >> A[i];
  sort(A, A + N);

  ll k2 = modpow(2, mod - 2);
  dp[0] = modpow(2, N);
  int s = 0;
  rep(i, N) {
    s = min(S, s + A[i]);
    for (int j = s; j >= A[i]; j--) {
      dp[j] = (dp[j] + dp[j - A[i]] * k2) % mod;
    }
  }

  co(dp[S] % mod);

  Would you please return 0;
}

Error: 0

Fixed submission:

#pragma GCC optimize("O3")
#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 int mod = 998244353;
const int IMAX = 100000;
constexpr ll modpow(ll A, ll B) {
  ll kotae = 1;
  while (B > 0) {
    if (B & 1)
      kotae = kotae * A % mod;
    A = A * A % mod;
    B >>= 1;
  }
  return kotae;
}

ll dp[3001];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, S;
  cin >> N >> S;

  int A[3000];
  rep(i, N) cin >> A[i];
  sort(A, A + N);

  ll k2 = modpow(2, mod - 2);
  dp[0] = modpow(2, N);
  int s = 0;
  rep(i, N) {
    s += min(S, s + A[i]);
    for (int j = s; j >= A[i]; j--) {
      dp[j] = (dp[j] + dp[j - A[i]] * k2) % mod;
    }
  }

  co(dp[S] % mod);

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

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)

using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 998244353;

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

  ll n, s;
  cin >> n >> s;
  vector<ll> a(n); // aは0-origin
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<vector<ll>> dp(n + 1, vector<ll>(s + 1, 0)); // dp[i][j] :
                                                      // Aiまで考えたときTとUの積集合の要素を添え字としたaの和がjであるような場合の数
                                                      // dpのiは1-origin
  dp[0][0] = 1;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < s + 1; j++) {
      dp[i + 1][j] += dp[i][j] * 2;
      dp[i + 1][j] %= mod;
      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 <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)

using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

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

  int n, s;
  cin >> n >> s;
  vector<int> a(n + 1); // aは0-origin
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<vector<int>> dp(n + 1, vector<int>(s)); // dp[i][j] :
                                                 // Aiまで考えたときTとUの積集合の要素を添え字としたaの和がjであるような場合の数
                                                 // dpのiは1-origin
  dp[0][0] = 1;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < s + 1; j++) {
      dp[i + 1][j] += dp[i][j] * 2;
      dp[i + 1][j] %= mod;
      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: Time Limit Exceeded

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

const ll MOD = 998244353;

int main() {
  ll n, s;
  std::cin >> n >> s;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }

  // iまでみてjとなる組み合わせ数
  vector<vector<ll>> dp(n + 1, vector<ll>(s + 1, 0));
  dp[0][0] = 1;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < s + 1; j++) {
      dp[i + 1][j] += dp[i][j] * 2;
      if (j - a[i] >= 0)
        dp[i + 1][j] += dp[i][j - a[i]];
      dp[i + 1][j] %= MOD;
    }
  }

  std::cout << dp[n][s] << std::endl;
}


Error: TLE

Fixed submission:

typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
const ll MOD = 998244353;
long long modpow(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}
int main() {
  ll n, s;
  std::cin >> n >> s;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  vector<vector<bool>> dp(n + 1, vector<bool>(s + 1, 0));
  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= s; j++) {
      dp[i + 1][j] = dp[i][j];
      if (j - a[i] >= 0)
        dp[i + 1][j] = dp[i + 1][j] || dp[i][j - a[i]];
    }
  }
  ll ans = 0;
  ll cnt = 0;
  function<void(int, int)> rec = [&](int l, int r) {
    if (l == 0 && r == 0) {
      ans += modpow(2, n - cnt);
      ans %= MOD;
      return;
    }
    if (dp[l][r]) {

      if (l - 1 >= 0)
        rec(l - 1, r);
      cnt++;
      if (l - 1 >= 0 && r - a[l - 1] >= 0)
        rec(l - 1, r - a[l - 1]);
      cnt--;
    }
  };
  rec(n, s);
  std::cout << ans << std::endl;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define sz 10010
#define MOD 998244353
#define ll long long

inline ll add(ll a, ll b) {
  a = ((a % MOD) + MOD) % MOD;
  b = ((b % MOD) + MOD) % MOD;
  return (a + b) % MOD;
}

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

  int n, s;
  cin >> n >> s;
  vector<int> a(n);
  for (auto &it : a)
    cin >> it;
  vector<vector<ll>> dp(n + 1, vector<ll>(s + 1, 0));
  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= s; j++) {
      dp[i + 1][j] = add(dp[i + 1][j], add(dp[i][j], dp[i][j]));
      if (j + a[i] <= s)
        dp[i + 1][j + a[i]] = add(dp[i + 1][j + a[i]], dp[i][j]);
    }
  }
  cout << dp[n][s];

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define sz 10010
#define MOD 998244353
#define ll long long

vector<ll> a;
ll n;
vector<vector<vector<ll>>> dp;

ll power(ll a, ll b) {
  a = a % MOD;
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % MOD;
    b >>= 1;
    a = (a * a) % MOD;
  }
  return res;
}

inline ll add(ll a, ll b) {
  a = ((a % MOD) + MOD) % MOD;
  b = ((b % MOD) + MOD) % MOD;
  return (a + b) % MOD;
}

ll recur(ll s, ll idx, ll cnt) {
  if (s < 0)
    return 0;
  if (s == 0)
    return power(2, n - cnt);
  if (idx == n)
    return (s == 0);
  if (dp[s][idx][cnt] != -1)
    return dp[s][idx][cnt];
  return dp[s][idx][cnt] =
             add(recur(s - a[idx], idx + 1, cnt + 1), recur(s, idx + 1, cnt));
}

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

  ll s, x;
  cin >> n >> s;
  dp.resize(s + 1, vector<vector<ll>>(n, vector<ll>(n, -1)));
  for (ll i = 0; i < n; i++) {
    cin >> x;
    a.push_back(x);
  }
  cout << recur(s, 0, 0);

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

#include <bits/stdc++.h>
#define ll long long
#define pii_ pair<int, int>
#define mp_ make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define show1(a) cout << #a << " = " << a << endl
#define show2(a, b) cout << #a << " = " << a << "; " << #b << " = " << b << endl
using namespace std;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
const int maxn = 3005;
const ll M = 998244353;
inline void fastio() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
ll qpow(ll a, ll b) {
  ll s = 1;
  while (b) {
    if (b & 1)
      s = (s * a) % M;
    a = (a * a) % M;
    b >>= 1;
  }
  return s;
}
int n, s, a[maxn];
ll f[maxn][maxn];

int main() {
  fastio();
  cin >> n >> s;
  rep(i, 1, n) cin >> a[i];
  f[0][0] = 1;
  rep(i, 1, n) {
    rep(j, 0, s) {
      f[i][j] = (f[i - 1][j] * 2) % M;
      if (j >= a[i]) {
        f[i][j] += f[i - 1][j - a[i]];
        f[i][j] %= M;
      }
    }
  }
  cout << f[n][s] << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pii_ pair<int, int>
#define mp_ make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define show1(a) cout << #a << " = " << a << endl
#define show2(a, b) cout << #a << " = " << a << "; " << #b << " = " << b << endl
using namespace std;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
const int maxn = 3005;
const ll M = 998244353;
inline void fastio() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
ll qpow(ll a, ll b) {
  ll s = 1;
  while (b) {
    if (b & 1)
      s = (s * a) % M;
    a = (a * a) % M;
    b >>= 1;
  }
  return s;
}
int n, s;
ll a[maxn], ans;

void dfs(int dfn, int now, int k) {
  if (now == s) {
    ans = (ans + qpow(2, n - k)) % M;
    return;
  }
  rep(i, dfn + 1, n) {
    if (a[i] + now > s)
      continue;
    dfs(i, a[i] + now, k + 1);
  }
}

int main() {
  fastio();
  cin >> n >> s;
  rep(i, 1, n) cin >> a[i];
  dfs(0, 0, 0);
  cout << ans << endl;
  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // const ll p = 1e9 + 7;
  const ll p = 998244353;

  ll n, s;
  cin >> n >> s;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++)
    cin >> a[i];

  vector<vector<ll>> dp(n, vector<ll>(s + 1, 0));
  dp[0][0] = 2;
  if (a[0] <= s)
    dp[0][a[0]] = 1;
  for (ll i = 1; i < n; i++) {
    for (ll j = 0; j <= s; j++) {
      dp[i][j] += dp[i - 1][j] * 2 % p;
      dp[i][j] %= p;
      if (j + a[i] <= s) {
        dp[i][j + a[i]] += dp[i - 1][j];
        dp[i][j + a[i]] %= p;
      }
    }
  }
  cout << dp[n - 1][s] << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }

// a^n mod p
// n > 0
// #include <cmath>
long long modpow(long long a, long long n, long long p) {
  a %= p;
  if (a == 0)
    return 0;
  if (a == 1)
    return 1;
  long long b = 1, cnt = 0;
  while (b < p && cnt < n) {
    b *= a;
    cnt++;
  }
  if (b < p)
    return b;
  b %= p;
  return modpow(b, n / cnt, p) * (long long)pow(a, n % cnt) % p;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // const ll p = 1e9 + 7;
  const ll p = 998244353;

  ll n, s;
  cin >> n >> s;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++)
    cin >> a[i];

  ll ans = 0;
  vector<vector<vector<ll>>> dp(n, vector<vector<ll>>(s, vector<ll>(0)));
  if (a[0] < s)
    dp[0][a[0]].push_back(1);
  else if (a[0] == s) {
    ans += modpow(2, n - 1, p);
    ans %= p;
  }
  for (ll i = 1; i < n; i++) {
    for (ll j = 0; j < s; j++) {
      for (auto k : dp[i - 1][j]) {
        dp[i][j].push_back(k);
        if (j + a[i] < s) {
          dp[i][j + a[i]].push_back(k + 1);
        } else if (j + a[i] == s) {
          ans += modpow(2, n - k - 1, p);
          ans %= p;
        }
      }
    }
    if (a[i] < s)
      dp[i][a[i]].push_back(1);
    else if (a[i] == s) {
      ans += modpow(2, n - 1, p);
      ans %= p;
    }
  }

  cout << ans << endl;
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

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

#define fr(i, n) for (int i = 0; i < n; i++)
#define sz(v) (v).begin(), (v).end()
#define prin(a) cout << #a << " = " << a << endl
#define all(v) (v).begin(), (v).end()
typedef long long ll;

const int N = 3e3 + 10;
ll dp[2][N], v[N];
#define cur_dp dp[(i + 1) & 1]
#define ant_dp dp[i & 1]
const ll MOD = 998244353;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, s;
  cin >> n >> s;
  fr(i, n) cin >> v[i];

  dp[0][0] = 1;
  fr(i, n) {
    for (int j = 0; j <= s; j++) {
      cur_dp[j] = 2 * ant_dp[j] % MOD;
      if (v[i] <= j)
        cur_dp[j] = (ant_dp[j - v[i]] + cur_dp[j]) % MOD;
    }
  }
  cout << dp[n & 1][s] << endl;
}

Error: 0

Fixed submission:

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

#define fr(i, n) for (int i = 0; i < n; i++)
#define sz(v) (v).begin(), (v).end()
#define prin(a) cout << #a << " = " << a << endl
#define all(v) (v).begin(), (v).end()
typedef long long ll;

const int N = 2e3 + 10;
ll dp[2][N], v[N];
#define cur_dp dp[(i + 1) & 1]
#define ant_dp dp[i & 1]
const ll MOD = 998244353;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, s;
  cin >> n >> s;
  fr(i, n) cin >> v[i];

  dp[0][0] = 1;
  fr(i, n) {
    for (int j = 0; j <= s; j++) {
      cur_dp[j] = 2 * ant_dp[j] % MOD;
      if (v[i] <= j)
        cur_dp[j] = (ant_dp[j - v[i]] + cur_dp[j]) % MOD;
    }
  }
  cout << dp[n & 1][s] << endl;
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

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

#define int long long
#define endl "\\n"
#define P pair<int, int>

const int mod = 998244353;

inline int add(int x, int y) {
  int res = x + y;
  if (res >= mod)
    res -= mod;
  return res;
}
inline int sub(int x, int y) {
  int res = x - y;
  if (res < 0)
    res += mod;
  return res;
}
inline int mul(int x, int y) {
  int res = (x % mod * y % mod) % mod;
  return res;
}

int modpow(int a, int b) {
  if (a == 0 || a == 1 || b == 1)
    return a;
  int res = 1;
  while (b) {
    if (b % 2)
      res = mul(res, a);
    b /= 2;
    a = mul(a, a);
  }
  return res;
}

const int N = 3003;
int pw[N];
const int MI2 = modpow(2, mod - 2);
int dp[N][N];
int n, s;
int a[N];

void solve() {
  cin >> n >> s;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  memset(dp, 0, sizeof dp);
  dp[0][0] = pw[n];
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= s; j++) {
      dp[i][j] = add(dp[i][j], dp[i - 1][j]);
      if (j - a[i] >= 0)
        dp[i][j] = add(dp[i][j], mul(MI2, dp[i - 1][j - a[i]]));
    }
  }
  cout << dp[n][s] << endl;
}

signed main() {

  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12);

  int T = 1;
  // cin >> T;
  pw[0] = 1;
  for (int i = 1; i < N; i++)
    pw[i] = mul(2, pw[i - 1]);
  for (int i = 1; i <= T; i++) {
    solve();
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\\n"

const int mod = 998244353;
const int N = 3003;

inline int add(int a, int b) {
  int res = a + b;
  if (res >= mod)
    res -= mod;
  return res;
}
inline int sub(int a, int b) {
  int res = a - b;
  if (res < 0)
    res += mod;
  return res;
}
inline int mul(int a, int b) { return (a * b) % mod; }

int pw[N];

void solve() {
  int n, s;
  cin >> n >> s;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  pair<bool, vector<int>> dp[n + 1][s + 1];
  dp[0][0].first = 1;
  dp[0][0].second.push_back(0);
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= s; j++)
      if (dp[i - 1][j].first) {
        dp[i][j].first = 1;
        // dp[i][j].second = dp[i-1][j].second;
        for (int x : dp[i - 1][j].second)
          dp[i][j].second.push_back(x);
        if (j + a[i - 1] <= s) {
          dp[i][j + a[i - 1]].first = 1;
          for (int x : dp[i - 1][j].second) {
            dp[i][j + a[i - 1]].second.push_back(x + 1);
          }
        }
      }
  }
  int ans = 0;
  for (int x : dp[n][s].second) {
    ans = add(ans, pw[n - x]);
  }
  cout << ans << endl;
}

signed main() {

  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12);

  int T = 1;
  // cin >> T;
  pw[0] = 1;
  for (int i = 1; i < N; i++)
    pw[i] = mul(2, pw[i - 1]);

  while (T--) {
    solve();
  }
  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int oo = 1e9 + 7;
const int mod = 998244353;
const double PI = acos(-1);

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

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

  for (auto &x : a)
    cin >> x;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= s; j++) {
      ll &val = dp[i + 1][j], val2 = dp[i][j];
      val += val2 * 2;
      val = (val + mod) % 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>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int oo = 1e9 + 7;
const int mod = 998244353;
const double PI = acos(-1);
ll c[3030][3030], dp[3030][3030];

void init() {
  for (int i = 0; i < 3030; i++) {
    for (int j = 0; j < 3030; j++) {
      c[i][j] = -1;
    }
  }
}

ll comb(ll a, ll b) {
  if (a == 0 || b == 0 || a <= b)
    return 1;
  if (c[a][b] != -1)
    return c[a][b];
  return c[a][a] = (comb(a - 1, b - 1) + comb(a - 1, b)) % mod;
}

int main() {
  init();
  ll n, k, ans = 0;
  cin >> n >> k;

  vector<vector<int>> dp(k + 10);

  dp[0].push_back(0);
  for (int i = 1; i <= n; i++) {
    ll aux;
    cin >> aux;
    for (int j = k - aux; j >= 0; j--) {
      if ((int)dp[j].size() > 0) {
        for (auto it : dp[j]) {
          dp[j + aux].push_back(it + 1);
        }
      }
    }
  }
  for (auto val : dp[k]) {
    for (int j = val; j <= n; j++)
      ans = (ans + comb(n - val, j - val)) % mod;
  }

  cout << ans << endl;
  return 0;
}