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

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

long long N, S;
long long A[3005];

#define DIV 998244353
long long memo[3005][9005];

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

  memo[0][0] = 1;
  for (long long i = 0; i < N; i++) {
    for (long long j = 0; j < 3002; j++) {
      if (memo[i][j]) {
        memo[i + 1][j] += 2 * memo[i][j];
        memo[i + 1][j] %= DIV;
        memo[i + 1][j + A[i]] += memo[i][j];
        memo[i + 1][j + A[i]] %= DIV;
      }
    }
  }

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


Error: TLE

Fixed submission:

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

long long N, S;
long long A[3005];

#define DIV 998244353

long long modpow(long long ori, long long po) {
  long long res = 1;
  while (po > 0) {
    if (po & 1) {
      res *= ori;
      res %= DIV;
    }
    ori *= ori;
    ori %= DIV;
    po >>= 1;
  }
  return res;
}

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

  map<pair<long long, long long>, long long> mapi;
  map<pair<long long, long long>, long long> nmapi;
  mapi[make_pair(0, 0)] = 1;

  for (long long i = 0; i < N; i++) {
    for (auto it = mapi.begin(); it != mapi.end(); it++) {
      long long num = it->first.first;
      long long sum = it->first.second;
      long long pat = it->second;
      nmapi[make_pair(num, sum)] += pat;
      if (sum + A[i] < 3003) {
        nmapi[make_pair(num + 1, sum + A[i])] += pat;
      }
    }
    mapi.clear();
    swap(mapi, nmapi);
  }

  long long ans = 0;
  for (auto it = mapi.begin(); it != mapi.end(); it++) {
    if (it->first.second == S) {
      ans += modpow(2, N - it->first.first) * it->second;
      ans %= DIV;
    }
    // cout << it->first.first << "," << it->first.second << "=" << it->second
    // << endl;
  }
  cout << ans << endl;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

long long int MOD = 998244353;

int N, S, A[3333];

long long int dp[3030][6030];

int main(void) {
  cin >> N >> S;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  // cout << "check" << endl;

  dp[0][0] = 1;

  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= 3000; j++) {
      dp[i][j] += dp[i - 1][j] * 2;
      dp[i][j] %= MOD;
      dp[i][j + A[i]] += dp[i - 1][j];
      dp[i][j + A[i]] %= MOD;
    }
  }

  /*for (int j = 0; j <= 10; j++) {
          cout << "dp[" << N << "][" << j << "]= " << dp[N][j] << endl;
  }*/

  long long int ans = dp[N][S];

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

long long int MOD = 998244353;

int N, S, A[3333];

long long int dp[2][3030][3030];

long long int P[3030];

int main(void) {
  cin >> N >> S;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  // cout << "check" << endl;

  P[0] = 1;
  for (int i = 1; i <= N; i++) {
    P[i] = P[i - 1] * 2;
    P[i] %= MOD;
  }

  dp[0][0][0] = 1;

  // cout << "check" << endl;

  for (int i = 1; i <= N; i++) {

    for (int k = 0; k <= N; k++) {
      for (int s = 0; s <= S; s++) {
        dp[i % 2][k][s] = 0;
      }
    }

    for (int k = 0; k <= N; k++) {
      for (int s = 0; s <= S; s++) {
        // cout << "check" << endl;
        if (s + A[i] <= S) {
          dp[i % 2][k + 1][s + A[i]] += dp[(i - 1 + 2) % 2][k][s];
          dp[i % 2][k + 1][s + A[i]] %= MOD;
        }
        dp[i % 2][k][s] += dp[(i - 1 + 2) % 2][k][s];
        dp[i % 2][k][s] %= MOD;
      }
    }
  }

  long long int ans = 0;

  for (int k = 1; k <= N; k++) {
    ans += ((dp[N % 2][k][S] * P[N - k]) % MOD);
    ans %= MOD;
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> P;
typedef priority_queue<P, vector<P>, greater<P>> P_queue;

const ll MOD = 998244353;
const ll mod = 1000000007;
const ll INF = 1e18;
const double PI = 3.1415926535897932;
vec dx = {1, 0, -1, 0};
vec dy = {0, 1, 0, -1};

#define REP(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a, b) a = (a + b) % MOD

ll dp[3005];

ll ruijou(ll n, ll k) {
  if (k == 0)
    return 1;
  ll K = k / 2;
  ll N = ruijou(n, K);
  N = (N * N) % MOD;
  if (k % 2)
    return (N * n) % MOD;
  return N;
}
int main() {
  ll N, S;
  cin >> N >> S;
  vec d(N);
  rep(i, N) cin >> d[i];
  dp[0] = 1;
  rep(i, N) for (int j = S; j >= 0; j--) {
    if (j + d[i] <= S)
      ADD(dp[j + d[i]], dp[j]);
    dp[j] = (dp[j] * 2) % MOD;
  }
  cout << dp[S] << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> P;
typedef priority_queue<P, vector<P>, greater<P>> P_queue;

const ll MOD = 998244353;
const ll mod = 1000000007;
const ll INF = 1e18;
const double PI = 3.1415926535897932;
vec dx = {1, 0, -1, 0};
vec dy = {0, 1, 0, -1};

#define REP(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a, b) a = (a + b) % MOD

ll dp[3005][3005];

ll ruijou(ll n, ll k) {
  if (k == 0)
    return 1;
  ll K = k / 2;
  ll N = ruijou(n, K);
  N = (N * N) % MOD;
  if (k % 2)
    return (N * n) % MOD;
  return N;
}
int main() {
  ll N, S;
  cin >> N >> S;
  vec d(N);
  rep(i, N) cin >> d[i];
  dp[0][0] = 1;
  rep(k, N) for (int i = k; i >= 0; i--) rep(j, S) if (dp[i][j]) {
    if (j + d[k] <= S)
      ADD(dp[i + 1][j + d[k]], dp[i][j]);
  }
  ll ans = 0;
  rep(i, N + 1) { ans = (ans + ruijou(2, N - i) * dp[i][S]) % MOD; }
  cout << ans << endl;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using ll = long long;
const ll MOD = 998244353;

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

ll minv(ll a) { return mpow(a, MOD - 2); }

int n, s;
ll val[3005];

int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> s;

  vector<int> a(n);
  for (auto &i : a) {
    cin >> i;

    for (int j = s - i; j >= 0; --j) {
      val[j + i] += val[j] * minv(2) % MOD;
      val[j + i] %= MOD;
    }

    val[i] += mpow(2, n - 1);
    val[i] %= MOD;
  }
  cout << val[s] % MOD;
}


Error: TLE

Fixed submission:

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

#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using ll = long long;
const ll MOD = 998244353;

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

int n, s;
set<pair<int, int>, greater<pair<int, int>>> m;
ll val[3005][3005];

int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> s;

  vector<int> ar(n);
  for (auto &i : ar)
    cin >> i;
  sort(all(ar));

  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    int a = ar[i];
    auto it = m.begin();
    while (it != m.end()) {
      auto nxt = next(it);
      pair<int, int> v = *it;
      if (a + v.first <= s) {
        val[v.first + a][v.second + 1] += val[v.first][v.second];
        val[v.first + a][v.second + 1] %= MOD;
        m.insert({v.first + a, v.second + 1});
      }
      it = nxt;
    }
    m.insert({a, 1});
    ++val[a][1];
  }
  for (int i = 1; i <= s; ++i) {
    ans += val[s][i] * mpow(2, n - i) % MOD;
    ans %= MOD;
  }
  cout << ans;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int mod = 998244353;

int P(int a, int b) {
  if (b == 0)
    return 1;
  if (b & 1)
    return (long long)P(a, b - 1) * a % mod;
  int t = P(a, b / 2);
  return (long long)t * t % mod;
}

const int O = P(2, mod - 2);

int H(int a) { return (long long)a * O % mod; }

const int S = 3003;
int n, s, x, dp[S];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> s;
  dp[0] = P(2, n);
  for (int i = 1; i <= n; ++i) {
    cin >> x;
    for (int i = s; i >= x; --i) {
      (dp[i] += H(dp[i - x])) %= mod;
    }
  }
  cout << dp[s] << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

const int mod = 998244353;

int P(int a, int b) {
  if (b == 0)
    return 1;
  if (b & 1)
    return (long long)P(a, b - 1) * a % mod;
  int t = P(a, b / 2);
  return (long long)t * t % mod;
}

int D(int a, int b) { return (long long)a * P(b, mod - 2) % mod; }

const int S = 3003;
int n, s, x, dp[S];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> s;
  dp[0] = P(2, n);
  for (int i = 1; i <= n; ++i) {
    cin >> x;
    for (int i = s; i >= x; --i) {
      (dp[i] += D(dp[i - x], 2)) %= mod;
    }
  }
  cout << dp[s] << endl;
  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> pll;
// const ll mod=1e9+7;
const ll mod = 998244353;
const ll inf = 1LL << 61;

ll mpow(ll x, ll n) {
  ll ans = 1;
  while (n > 0) {
    if (n & 1) {
      ans = ans * x % mod;
    }
    x = x * x % mod;
    n >>= 1;
  }
  return ans;
}

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> pll;
// const ll mod=1e9+7;
const ll mod = 998244353;
const ll inf = 1LL << 61;

ll mpow(ll x, ll n) {
  ll ans = 1;
  while (n > 0) {
    if (n & 1) {
      ans = ans * x % mod;
    }
    x = x * x % mod;
    n >>= 1;
  }
  return ans;
}

int main() {
  ll n, s;
  cin >> n >> s;
  vec a(n);
  for (ll i = 0; i < n; i++)
    cin >> a[i];
  vector<vector<map<ll, ll>>> dp(n + 1, vector<map<ll, ll>>(s + 1));
  set<ll> al;
  al.insert(0);
  dp[0][0][0] = 1;
  for (ll i = 0; i < n; i++) {
    for (ll j : al)
      dp[i + 1][j] = dp[i][j];
    set<ll> tmp;
    for (ll j : al) {
      if (j + a[i] <= s) {
        for (auto p : dp[i][j]) {
          ll cnt = p.first;
          ll val = p.second;
          tmp.insert(j + a[i]);
          (dp[i + 1][j + a[i]][cnt + 1] += val) %= mod;
        }
      }
    }
    for (ll j : tmp) {
      al.insert(j);
    }
  }
  ll ans = 0;
  for (auto p : dp[n][s]) {
    ll cnt = p.first;
    ll val = p.second;
    (ans += val * mpow(2, n - cnt) % mod) %= mod;
  }
  cout << ans << endl;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
ll mod = 998244353;
ll power(ll a, ll b) {
  ll result = 1;
  while (b > 0) {
    if (b % 2)
      result = (result * a) % mod;
    a = (a * a) % mod;
    b /= 2;
  }
  return result;
}
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n + 1);
  for (ll i = 1; i <= n; i++)
    cin >> a[i];
  ll p = power(2, mod - 2);
  vector<vector<ll>> dp(n + 1, vector<ll>(k + 3));
  dp[0][0] = power(2, n);
  // cout<<dp[0][0]<<endl;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= k; j++) {
      dp[i][j] = dp[i - 1][j];
      if (j - a[i] >= 0) {
        (dp[i][j] += ((dp[i - 1][j - a[i]]) * p) % mod) %= mod;
      }
    }
  }
  cout << dp[n][k] << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
ll mod = 998244353;
ll power(ll a, ll b) {
  ll result = 1;
  while (b > 0) {
    if (b % 2)
      result = (result * a) % mod;
    a = (a * a) % mod;
    b /= 2;
  }
  return result;
}
ll invert(ll a) { return power(a, mod - 2); }
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n + 1);
  for (ll i = 1; i <= n; i++)
    cin >> a[i];
  vector<vector<ll>> dp(n + 1, vector<ll>(k + 3));
  dp[0][0] = power(2, n);
  // cout<<dp[0][0]<<endl;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= k; j++) {
      dp[i][j] = dp[i - 1][j];
      if (j - a[i] >= 0) {
        (dp[i][j] += ((dp[i - 1][j - a[i]]) * invert(2)) % mod) %= mod;
      }
    }
  }
  cout << dp[n][k] << endl;
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

const int MOD = 998244353;
int n, s, a[3000];
int dp[3001];

int po(int x, int y) {
  int ans = 1;
  while (y > 0) {
    if (y & 1)
      ans = static_cast<long>(ans) * x % MOD;
    x = static_cast<long>(x) * x % MOD;
    y >>= 1;
  }
  return ans;
}

int main() {
  scanf("%d %d", &n, &s);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  int inv2 = po(2, MOD - 2);
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = s; j >= a[i]; j--) {
      dp[j] = (dp[j] + static_cast<long>(dp[j - a[i]]) * inv2 % MOD) % MOD;
    }
  }

  printf("%ld\\n", static_cast<long>(dp[s]) * po(2, n) % MOD);
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <queue>
#include <utility>
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;

const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int h, w, k, x1, x2, y1, y2;
char s[1000001];
P d[1000000][4];
priority_queue<PP, vector<PP>, greater<PP>> q;

int main() {
  scanf("%d %d %d", &h, &w, &k);
  scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
  x1--;
  y1--;
  x2--;
  y2--;
  for (int i = 0; i < h; i++)
    scanf("%s", &s[i * w]);

  for (int i = 0; i < h * w; i++)
    fill(d[i], d[i] + 4, P((int)1e9, 0));

  for (int i = 0; i < 4; i++) {
    int a = x1 + dx[i], b = y1 + dy[i];
    if (0 <= a && a < h && 0 <= b && b < w && s[a * w + b] == '.') {
      d[a * w + b][i] = P(1, 1);
      q.emplace(P(1, 1), 10000000 * i + a * w + b);
    }
  }

  while (!q.empty()) {
    int z = q.top().second;
    int x = z % 10000000;
    z /= 10000000;
    int y = x % w;
    x /= w;
    P p = q.top().first;
    q.pop();
    if (d[x * w + y][z] != p)
      continue;
    for (int i = 0; i < 4; i++) {
      int a = x + dx[i], b = y + dy[i];
      if (0 <= a && a < h && 0 <= b && b < w && s[a * w + b] == '.') {
        P tmp = p;
        if (i != z || tmp.second == k) {
          tmp.second = 1;
          tmp.first++;
        } else
          tmp.second++;
        if (tmp >= d[a * w + b][i])
          continue;
        d[a * w + b][i] = tmp;
        q.emplace(tmp, 10000000 * i + a * w + b);
      }
    }
  }

  int ans = 1e9;
  for (int i = 0; i < 4; i++)
    ans = min(ans, d[x2 * w + y2][i].first);
  printf("%d\\n", ans == 1e9 ? -1 : ans);
  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define dl double
#define mp make_pair
#define pb push_back
using namespace std;

//***********************************************************************

// hash struct for unordered_map
struct hash_pair {
  template <class T1, class T2> size_t operator()(const pair<T1, T2> &p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};

int MAXNUM = 5e3 + 5;
vector<int> vis(MAXNUM);
vector<int> pr;
void sieve() {
  pr.push_back(2);
  for (ll i = 3; i < MAXNUM; i += 2)
    if (!vis[i]) {
      pr.push_back(i);
      for (ll j = i * i; j < MAXNUM; j += 2 * i)
        vis[j] = true;
    }
}
//************************************************************************

ll mod = 998244353;

void solve() {
  ll n, s;
  cin >> n >> s;
  vector<ll> v(n);
  vector<vector<ll>> dp(n + 100, vector<ll>(s + 100, 0));
  ll p = 1;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    p *= 2;
    p %= mod;
    dp[i][0] = p;
  }
  dp[0][v[0]] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= s; j++) {
      dp[i][j] = (2 * dp[i - 1][j]) % mod;
      if (j >= v[i]) {
        dp[i][j] += dp[i - 1][j - v[i]];
        dp[i][j] %= mod;
      }
    }
  }
  cout << dp[n - 1][s] << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t;
  // cin >> t;
  t = 1;
  while (t--) {
    solve();
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define dl double
#define mp make_pair
#define pb push_back
using namespace std;

//***********************************************************************

// hash struct for unordered_map
struct hash_pair {
  template <class T1, class T2> size_t operator()(const pair<T1, T2> &p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};

int MAXNUM = 5e3 + 5;
vector<int> vis(MAXNUM);
vector<int> pr;
void sieve() {
  pr.push_back(2);
  for (ll i = 3; i < MAXNUM; i += 2)
    if (!vis[i]) {
      pr.push_back(i);
      for (ll j = i * i; j < MAXNUM; j += 2 * i)
        vis[j] = true;
    }
}
//************************************************************************

ll mod = 998244353;

void solve() {
  ll n, s;
  cin >> n >> s;
  vector<ll> v(n);
  vector<vector<ll>> dp(n + 5, vector<ll>(s + 5));
  ll p = 1;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    p *= 2;
    p %= mod;
    dp[i][0] = p;
  }
  dp[0][v[0]] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= s; j++) {
      dp[i][j] = (2 * dp[i - 1][j]) % mod;
      if (j >= v[i]) {
        dp[i][j] += dp[i - 1][j - v[i]];
        dp[i][j] %= mod;
      }
    }
  }
  cout << dp[n - 1][s] << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t;
  // cin >> t;
  t = 1;
  while (t--) {
    solve();
  }

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

#include <bits/stdc++.h>

int mod = 998244353;

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

  std::vector<std::vector<long long>> dp(N + 1,
                                         std::vector<long long>(S + 1, 0));
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= S; j++) {
      dp[i][j] = (2 * dp[i - 1][j]) % mod;
      if (j >= A[i - 1]) {
        dp[i][j] = (dp[i][j] + dp[i - 1][j - A[i - 1]]) % mod;
      }
      if (j == 0 || j == A[i - 1]) {
        dp[i][j] = (dp[i][j] + 1) % mod;
      }
    }
    // for(int j=0; j<=S; j++){
    //     std::cout << dp[i][j] << " ";
    // }
    // std::cout << std::endl;
  }

  std::cout << dp[N][S] << std::endl;
  ;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

long long modnum = 998244353;

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

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

  std::vector<int> sum_cnt;
  sum_cnt.push_back(0);
  std::vector<std::vector<int>> sum_index;
  std::vector<int> a;
  a.push_back(0);
  sum_index.push_back(a);
  for (int i = 0; i < N; i++) {
    int size = sum_cnt.size();
    for (int j = 0; j < size; j++) {
      int sum_tmp = sum_cnt[j] + A[i];
      std::vector<int> index_tmp;
      index_tmp = sum_index[j];
      index_tmp.push_back(i);
      sum_cnt.push_back(sum_tmp);
      sum_index.push_back(index_tmp);
    }
  }

  long long ans = 0;
  for (int i = 0; i < sum_cnt.size(); i++) {
    if (sum_cnt[i] == S) {
      std::vector<int> index_tmp;
      index_tmp = sum_index[i];
      long long tmp = modpow(2, N - index_tmp.size() + 1);
      ans = (ans + tmp) % modnum;
    }
  }

  std::cout << ans << std::endl;

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

#pragma GCC optimize("Ofast")
#include <algorithm>
#include <stdio.h>
using namespace std;
long long num[3005], dp[3005][3005] = {0}, mod = 998244353;
int main() {
  long long i, j, n, s;
  scanf("%lld%lld", &n, &s);
  for (i = 1; i <= n; i++)
    scanf("%lld", &num[i]);
  dp[0][0] = 1;
  for (i = 1; i <= n; i++) {
    for (j = 0; j <= s; j++) {
      dp[i][j] = dp[i - 1][j] * 2 % mod;
      if (j >= num[i])
        dp[i][j] = (dp[i][j] + dp[i - 1][j - num[i]]) % mod;
    }
  }
  printf("%lld\\n", dp[n][s]);
}

Error: TLE

Fixed submission:

#pragma GCC optimize("Ofast")
#include <algorithm>
#include <stdio.h>
#include <vector>
using namespace std;
long long num[3005], mod = 998244353;
vector<long long> g[3005], temp[3005];
long long power(long long n, long long m) {
  if (!m)
    return 1;
  long long v = power(n, m >> 1);
  if (m & 1)
    return v * v % mod * n % mod;
  return v * v % mod;
}
int main() {
  long long i, j, n, s;
  scanf("%lld%lld", &n, &s);
  for (i = 0; i < n; i++)
    scanf("%lld", &num[i]);
  for (i = 0; i < n; i++) {
    for (j = 1; j <= s; j++)
      temp[j].clear();
    temp[num[i]].emplace_back(1);
    for (j = 1; j + num[i] <= s; j++)
      for (auto x : g[j])
        temp[j + num[i]].emplace_back(x + 1);
    for (j = 1; j <= s; j++)
      for (auto x : temp[j])
        g[j].emplace_back(x);
  }
  long long ans = 0;
  for (auto x : g[s])
    ans = (ans + power(2, n - x)) % mod;
  printf("%lld\\n", ans);
}