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

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

const int 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;
}

long long modinv(long long a) { return modpow(a, MOD - 2); }

int main() {
  int N, S;
  cin >> N >> S;
  vector<ll> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  vector<vector<ll>> memo(N, vector<ll>(S + 1, 0));

  memo[0][0] = modpow(2, N);
  if (A[0] <= S)
    memo[0][A[0]] = (memo[0][0] * modinv(2)) % MOD;
  for (int i = 1; i < N; i++) {
    for (int j = 0; j <= S; j++) {
      memo[i][j] = memo[i - 1][j];
      if (j - A[i] >= 0) {
        memo[i][j] += (memo[i - 1][j - A[i]] * modinv(2)) % MOD;
        memo[i][j] %= MOD;
      }
    }
  }
  // for (int i = 0; i < N; i++) {
  //     for (int j = 0; j <= S; j++) {
  //         cout << memo[i][j] << ' ';
  //     }
  //     cout << endl;
  // }
  cout << memo[N - 1][S] << endl;
}

Error: TLE

Fixed submission:

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

const int 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() {
  int N, S;
  cin >> N >> S;
  vector<ll> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  vector<vector<map<int, int>>> memo(N, vector<map<int, int>>(S + 1));
  if (A[0] <= S)
    memo[0][A[0]][1] += 1;

  for (int i = 1; i < N; i++) {
    if (A[i] <= S)
      memo[i][A[i]][1] += 1;
    for (int j = 0; j <= S; j++) {
      for (auto x : memo[i - 1][j]) {
        memo[i][j][x.first] += x.second;
      }
      if (j - A[i] >= 0) {
        for (auto x : memo[i - 1][j - A[i]]) {
          memo[i][j][x.first + 1] += x.second;
        }
      }
    }
  }
  // for (int i = 0; i < N; i++) {
  //     for (int j = 0; j <= S; j++) {
  //         for (auto x : memo[i][j]) printf("%d %d %d %d : ", i, j, x.first,
  //         x.second); printf("\\n");
  //     }
  // }
  ll ans = 0;
  for (auto x : memo[N - 1][S]) {
    ans += x.second * modpow(2, N - x.first);
    ans = (MOD + ans) % MOD;
  }
  cout << ans << endl;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const lint mod = 998244353;
lint dp[3005][3005];

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

  lint N, S;
  cin >> N >> S;
  vector<lint> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  dp[0][0] = 1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= 3001; j++) {
      dp[i + 1][j] += 2ll * dp[i][j] % mod;
      dp[i + 1][j] %= mod;
      dp[i + 1][min(3001ll, j + A[i])] += dp[i][j];
      dp[i + 1][min(3001ll, j + A[i])] %= mod;
    }
  }

  cout << dp[N][S] << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

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

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

  vector<vector<lint>> dp(3005, vector<lint>(3005, 0));
  dp[0][0] = 1;

  const lint mod = 998244353;

  lint N, S;
  cin >> N >> S;
  vector<lint> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= 3000; j++) {
      dp[i + 1][j] += 2 * dp[i][j];
      if (j + A[i] <= 3000) {
        dp[i + 1][j + A[i]] += dp[i][j];
      }
    }
    for (int j = 0; j <= 3000; j++) {
      while (dp[i][j] >= mod)
        dp[i][j] -= mod;
    }
  }

  cout << dp[N][S] << "\\n";
  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// const ll MOD=(ll)1e9+7;
const ll MOD = (ll)998244353;
const ll INF = (ll)1e18 + 10;
const double PI = 2.0 * acos(0);

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int dy[] = {-1, 1, 0, 0};
int dx[] = {0, 0, -1, 1};

ll dp[3010][3010];
void solve(int ca) {
  int N, S;
  cin >> N >> S;
  vector<int> a(N);
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
  }
  dp[0][0] = 1;

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j <= S; ++j) {
      (dp[i + 1][j] += 2ll * dp[i][j]) %= MOD;
      if (j + a[i] <= S) {
        (dp[i + 1][j + a[i]] += dp[i][j]) %= MOD;
      }
    }
  }

  cout << dp[N][S] << endl;
}

// #define MULTI
int main() {
#ifdef MULTI
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    solve(i + 1);
  }
#else
  solve(0);
#endif
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// const ll MOD=(ll)1e9+7;
const ll MOD = (ll)998244353;
const ll INF = (ll)1e18 + 10;
const double PI = 2.0 * acos(0);

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int dy[] = {-1, 1, 0, 0};
int dx[] = {0, 0, -1, 1};

bool dp[3010][3010];
int a[3010];
ll ans = 0ll;
int N;

long long modpow(long long ab, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * ab % mod;
    ab = ab * ab % mod;
    n >>= 1;
  }
  return res;
}

void dfs(int n, int val, int cnt) {
  // cout<<n<<" "<<val<<" "<<cnt<<endl;
  if (val == 0) {
    // cout<<n<<" "<<cnt<<endl;
    (ans += modpow(2ll, (ll)N - cnt, MOD)) %= MOD;
    return;
  }
  if (n == 0)
    return;
  if (dp[n - 1][val]) {
    dfs(n - 1, val, cnt);
  }
  if (val - a[n - 1] >= 0 && dp[n - 1][val - a[n - 1]]) {
    dfs(n - 1, val - a[n - 1], cnt + 1);
  }
}

void solve(int ca) {
  int S;
  cin >> N >> S;
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
  }

  memset(dp, 0, sizeof(dp));

  dp[0][0] = true;

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < S + 1; ++j) {
      if (!dp[i][j])
        continue;
      dp[i + 1][j] = true;
      if (j + a[i] <= S)
        dp[i + 1][j + a[i]] = true;
    }
  }

  dfs(N, S, 0);

  cout << ans << endl;
}

// #define MULTI
int main() {
#ifdef MULTI
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    solve(i + 1);
  }
#else
  solve(0);
#endif
  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  long long int F[N + 1][S + 1];
  F[0][0] = 1;
  for (int j = 1; j < S + 1; j++) {
    F[0][j] = 0;
  }

  for (int i = 1; i < N + 1; i++) {
    for (int j = 0; j < S + 1; j++) {
      if (j - A[i - 1] < 0) {
        F[i][j] = F[i - 1][j] * 2;
      } else {
        F[i][j] = F[i - 1][j] * 2 + F[i - 1][j - A[i - 1]];
      }
      F[i][j] = F[i][j] % 998244353;
    }
  }

  cout << F[N][S];
  return 0;
}


Error: TLE

Fixed submission:

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

void node(int sum, int s, long int *a, long int *c, int n, int x, int y);
int X(int x, int y);

int main() {
  int N, S;
  long long int O = 0;
  cin >> N >> S;
  long int A[N], C[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  for (int i = 0; i < N; i++) {
    C[i] = 0;
  }

  sort(A, A + N, greater<>());

  node(0, S, A, C, N, -1, 0);

  //  for(int i=0;i<N;i++){
  //  cout << i+1 << ":" << C[i] <<endl;
  //  }

  long long int z = 1;
  for (int i = 1; i < N + 1; i++) {
    if (z > 998244353) {
      z = z - 998244353;
    }
    O = O + C[N - i] * z;
    O = O % 998244353;

    z = z * 2;
  }

  cout << O;
  return 0;
}

// sum : ここまでの合計
// s : 与えられたS
// a : 与えられた数列A
// c : チェック用数列
// n ; 与えられたN
// x : 今までに足した最大の数字の番号
// y : 今までに何個足したか

void node(int sum, int s, long int *a, long int *c, int n, int x, int y) {
  y++;
  for (int i = x + 1; i < n; i++) {
    if (sum + a[i] == s) {
      c[y - 1]++;
    } else if (sum + a[i] < s) {
      node(sum + a[i], s, a, c, n, i, y);
    }
  }
}

int X(int x, int y) {
  int a = 1;
  for (int i = 0; i < y; i++) {
    a = a * x;
  }
  return a;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
const ll mod = 998244353;

int main() {
  ll n, s;
  cin >> n >> s;
  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i];
  vector<vector<ll>> dp(n + 1, vector<ll>(s + 1, 0));
  dp[0][0] = 1;
  rep(i, 0, n) {
    rep(j, 0, s + 1) {
      dp[i + 1][j] += 2 * dp[i][j];
      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;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
const ll mod = 998244353;

ll mod_pow(ll a, ll n, ll mod) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1)
      ret = (ret * (a % mod)) % mod;
    a = ((a % mod) * (a % mod)) % mod;
    n = n >> 1;
  }
  return ret;
}

int main() {
  ll n, s;
  cin >> n >> s;
  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i];
  vector<vector<ll>> dp1(n + 1, vector<ll>(s + 1, 0)),
      dp2(n + 1, vector<ll>(s + 1, 0));
  dp2[0][0] = 1;
  dp1[0][0] = 1;
  rep(i, 0, n) {
    rep(j, 0, s + 1) {
      if (j + a[i] > s)
        break;
      rep(k, 0, n) {
        dp1[k + 1][j + a[i]] += dp2[k][j];
        dp1[k + 1][j + a[i]] %= mod;
      }
    }
    rep(k, 0, n + 1) {
      rep(j, 0, s + 1) { dp2[k][j] = dp1[k][j]; }
    }
  }
  ll ans = 0;
  rep(i, 1, n + 1) {
    ans += (dp2[i][s] * mod_pow(2, n - i, mod)) % mod;
    ans %= mod;
  }
  cout << ans << endl;
  /*
  rep(i, 0, n+1) {
      rep(j, 0, s+1) cerr << dp2[i][j] << " ";
      cerr << endl;
  }
  */
  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
#define f first
#define s second
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define INF (ll)1e9 + 100
#define LLINF (ll)1e18
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)

ll n, s, arr[3005], mod = 998244353, dp[3005][3005];

int main() {
  fastio;
  cin >> n >> s;
  FOR(i, 1, n) cin >> arr[i];
  dp[0][0] = 1;
  FOR(i, 1, n) FOR(j, 0, s) {
    dp[i][j] += 2 * dp[i - 1][j];
    dp[i][j] %= mod;
    if (arr[i] <= j) {
      dp[i][j] += dp[i - 1][j - arr[i]];
      dp[i][j] %= mod;
    }
  }
  cout << dp[n][s];
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for (int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for (int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define INF (int)1e9 + 100
#define LLINF (ll)1e18
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)

int n, s, arr[3005];
bool dp[3005][3005];
ll ans, mod = 998244353, cur;

ll qexp(ll a, ll b) {
  a %= mod;
  ll res = 1, base = a;
  while (b) {
    if (b & 1) {
      res *= base;
      res %= mod;
    }
    base *= base;
    base %= mod;
    b >>= 1;
  }
  return res % mod;
}

void gen(int idx, int val) {
  if (idx == 0) {
    if (val == 0) {
      ans += qexp(2, n - cur);
      ans %= mod;
    }
    return;
  }
  if (arr[idx] <= val and dp[idx - 1][val - arr[idx]]) {
    cur++;
    gen(idx - 1, val - arr[idx]);
    cur--;
  }
  gen(idx - 1, val);
}

int main() {
  fastio;
  cin >> n >> s;
  dp[0][0] = 1;
  FOR(i, 1, n) {
    cin >> arr[i];
    FOR(j, 0, s) if (dp[i - 1][j]) {
      dp[i][j] = 1;
      if (j + arr[i] <= s)
        dp[i][j + arr[i]] = 1;
    }
  }
  gen(n, s);
  cout << ans;
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

const int N = 3e3 + 23;
const int mod = 998244353;

long long dp[N][N];
int a[N];

void solve() {
  int n, s;
  scanf("%d%d", &n, &s);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  dp[0][0] = 1;
  for (int i = 0; i <= s; ++i) {
    for (int j = 0; j < n; ++j) {
      dp[i][j + 1] = (dp[i][j + 1] + dp[i][j] * 2) % mod;
      if (i + a[j] <= s)
        dp[i + a[j]][j + 1] = (dp[i + a[j]][j + 1] + dp[i][j]) % mod;
    }
  }
  printf("%lld", dp[s][n]);
}

int main() {
  init();
  int t = 1; // scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Error: WA

Fixed submission:

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

const int N = 3e3 + 23;
const int mod = 998244353;

long long dp[N][N];
int a[N];

void solve() {
  int n, s;
  scanf("%d%d", &n, &s);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  dp[0][0] = 1;
  for (int i = 0; i <= s; ++i) {
    for (int j = 0; j < n; ++j) {
      dp[i][j + 1] = (dp[i][j + 1] + dp[i][j] * 2) % mod;
      if (i + a[j] <= N)
        dp[i + a[j]][j + 1] = (dp[i + a[j]][j + 1] + dp[i][j]) % mod;
    }
  }
  printf("%lld", dp[s][n]);
}

int main() {
  init();
  int t = 1; // scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define int long long
int dp[3123][3123], n, s, v[3123];
// dp[i][j]:sum:2^(n-k)*(i-1番目まで見てk個使って合計がjになる個数)
// dp[i+1][j]=dp[i][j-v[i]]/2+dp[i][j]
// 初期値はdp[0][0]=2^n
const int MOD = 998244353;
int pw(int n, int k) {
  assert(k >= 0);
  int res = 1;
  while (k) {
    if (k & 1)
      (res *= n) %= MOD;
    (n *= n) %= MOD;
    k >>= 1;
  }
  return res;
}
int f(int i, int j) {
  if (j < 0)
    return 0;
  if (!i)
    return pw(2, n) * (!j);
  if (~dp[i][j])
    return dp[i][j];
  return dp[i][j] =
             (f(i - 1, j - v[i - 1]) * pw(2, MOD - 2) + f(i - 1, j)) % MOD;
}

signed main() {
  memset(dp, -1, sizeof(dp));
  cin >> n >> s;
  for (int i = 0; i < n; i++)
    cin >> v[i];
  cout << f(n, s) << endl;
}


Error: TLE

Fixed submission:

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

#define int long long
int dp[3123][3123], n, s, v[3123];
// dp[i][j]:sum:2^(n-k)*(i-1番目まで見てk個使って合計がjになる個数)
// dp[i+1][j]=dp[i][j-v[i]]/2+dp[i][j]
// 初期値はdp[0][0]=2^n
const int MOD = 998244353;
int pw(int n, int k) {
  assert(k >= 0);
  int res = 1;
  while (k) {
    if (k & 1)
      (res *= n) %= MOD;
    (n *= n) %= MOD;
    k >>= 1;
  }
  return res;
}
int f(int i, int j) {
  if (j < 0)
    return 0;
  if (!i)
    return pw(2, n) * (!j);
  if (~dp[i][j])
    return dp[i][j];
  return (f(i - 1, j - v[i - 1]) * pw(2, MOD - 2) + f(i - 1, j)) % MOD;
}

signed main() {
  memset(dp, -1, sizeof(dp));
  cin >> n >> s;
  for (int i = 0; i < n; i++)
    cin >> v[i];
  cout << f(n, s) << endl;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long mod = 998244353;
  int n, s;
  cin >> n >> s;
  long long d[3005][3005];
  int a[3005];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int j = 0; j <= n; j++) {
    for (int k = 0; k <= s; k++) {
      d[j][k] = 0;
    }
  }
  d[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int k = 0; k <= s - a[i]; k++)
      d[i + 1][k + a[i]] = d[i][k];
    for (int k = 0; k <= s; k++)
      d[i + 1][k] = (d[i + 1][k] + 2 * d[i][k]) % mod;
  }
  cout << d[n][s] << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  long long mod = 998244353;
  int n, s;
  cin >> n >> s;
  long long d[3005][3005];
  int a[3005];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int j = 0; j <= n; j++) {
    for (int k = 0; k <= s; k++) {
      d[j][k] = 0;
    }
  }
  d[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++) {
        if (d[j][k] > 0) {
          d[j + 1][k + a[i]] += d[j][k];
          d[j + 1][k + a[i]] %= mod;
        }
      }
    }
  }

  long long ans = 0;
  long long p = 1;
  for (int j = n; j >= 0; j--) {
    long long x = (p * d[j][s]) % mod;
    ans = (ans + x) % mod;
    p = (2 * p) % mod;
  }
  cout << ans << endl;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

Error: TLE

Fixed submission:

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

int main() {
  int n, s;
  cin >> n >> s;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> mod_pow2(n + 1);
  ll MOD = 998244353;
  mod_pow2[0] = 1;
  rep(i, n) mod_pow2[i + 1] = mod_pow2[i] * 2 % MOD;
  vector<vector<ll>> dp(n + 1, vector<ll>(s + 1, 0));
  dp[0][0] = 1;
  rep(i, n) for (int j = i; j >= 0; j--) rep(k, s) {
    if (k + a[i] > s)
      break;
    dp[j + 1][k + a[i]] = (dp[j + 1][k + a[i]] + dp[j][k]) % MOD;
  }
  ll ans = 0;
  rep(i, n) ans = (ans + dp[i + 1][s] * mod_pow2[n - i - 1] % MOD) % MOD;
  cout << ans << endl;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
const int N = 998244353;
int n, s, temp, x, f[2][3005], a[3005];
int main() {
  scanf("%d%d", &n, &s);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  f[0][0] = 2;
  f[0][a[1]] = 1;
  for (int i = 2; i <= n; ++i) {
    x ^= 1;
    for (int j = 0; j < a[i]; ++j) {
      f[x][j] = f[x ^ 1][j] << 1;
      if (f[x][j] > N)
        f[x][j] -= N;
    }
    for (int j = a[i]; j <= s; ++j) {
      f[x][j] = f[x ^ 1][j] << 1;
      if (f[x][j] > N)
        f[x][j] -= N;
      f[x][j] += f[x ^ 1][j - a[i]];
      if (f[x][j] > N)
        f[x][j] -= N;
    }
  }
  printf("%d", f[x][s]);
}

Error: TLE

Fixed submission:

#include <cstdio>
const int N = 998244353;
int n, m, s, ans, a[3005], pow[3005], b[3005], sum[3005];
void dfs(int x, int y) {
  if (y > s)
    return;
  if (y + sum[x] < s)
    return;
  if (y == s) {
    ans += pow[n - m];
    if (ans > N)
      ans -= N;
    return;
  }
  if (x > n)
    return;
  dfs(x + 1, y);
  ++m;
  dfs(x + 1, y + a[x]);
  --m;
}
int main() {
  // freopen("in.txt","r",stdin);
  scanf("%d%d", &n, &s);
  pow[0] = 1;
  for (int i = 1; i <= n; ++i) {
    pow[i] = pow[i - 1] << 1;
    if (pow[i] > N)
      pow[i] -= N;
    scanf("%d", &a[i]);
  }
  for (int i = n; i; --i)
    sum[i] = sum[i + 1] + a[i];
  dfs(1, 0);
  printf("%d", ans);
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define FOR(i, j, k, in) for (int i = j; i < k; i += in)
#define RFOR(i, j, k, in) for (int i = j; i >= k; i -= in)
#define rep(i, j) FOR(i, 0, j, 1)
#define rrep(i, j) RFOR(i, j, 0, 1)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define endl "\\n"
#define MOD 998244353
#define DEB(x) cout << "##" << x << "##" << endl;
ll fastex(int a, int b) {
  if (b == 0)
    return 1;
  ll t = fastex(a, b / 2);
  if (b % 2 == 0)
    return (t * t) % MOD;
  return (((t * t) % MOD) * a) % MOD;
}
ll modinv(int x) { return fastex(x, MOD - 2); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, sum;
  cin >> n >> sum;
  int ar[n + 1];
  // ar[0]=0;
  rep(i, n) cin >> ar[i];
  int dp[3005][3005] = {0};
  dp[0][0] = fastex(2, n) % MOD;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= sum; j++) {
      dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;
      // cout<<dp[i+1][j]<<" ";

      if (j + ar[i] <= sum) {
        dp[i + 1][j + ar[i]] =
            (dp[i + 1][j + ar[i]] + dp[i][j] * modinv(2)) % MOD;
        // cout<<dp[i+1][j+ar[i]]<<" ";
      }
    }
    cout << endl;
  }

  cout << dp[n][sum];
  return 0;
}

Error: WA

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define FOR(i, j, k, in) for (int i = j; i < k; i += in)
#define RFOR(i, j, k, in) for (int i = j; i >= k; i -= in)
#define rep(i, j) FOR(i, 0, j, 1)
#define rrep(i, j) RFOR(i, j, 0, 1)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define endl "\\n"
#define MOD 998244353
#define DEB(x) cout << "##" << x << "##" << endl;
ll fastex(int a, int b) {
  if (b == 0)
    return 1;
  ll t = fastex(a, b / 2);
  if (b % 2 == 0)
    return (t * t) % MOD;
  return (((t * t) % MOD) * a) % MOD;
}
ll modinv(int x) { return fastex(x, MOD - 2); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n, sum;
  cin >> n >> sum;
  int ar[n + 1];
  // ar[0]=0;
  rep(i, n) cin >> ar[i + 1];
  int dp[305][305] = {0};
  dp[0][0] = fastex(2, n) % MOD;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= sum; j++) {
      dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;
      if (i >= 1) {
        if (j + ar[i] <= sum) {
          dp[i + 1][j + ar[i]] =
              (dp[i + 1][j + ar[i]] + dp[i][j] * modinv(2)) % MOD;
        }
      }
    }
  }
  cout << dp[n + 1][sum];
  return 0;
}