Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

// 高知能系Vtuberの高井茅乃です。
// Twitter: https://twitter.com/takaichino
// YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i, n) for (int i = 0; i < n; i++)
#define REP1(i, n) for (int i = 1; i <= n; i++)
#define MODA 998244353

// つねに10億7などの剰余をとる構造体
// 参考: https://www.youtube.com/watch?v=L8grWxBlIZ4&t=9858
// 参考:
// https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a#4-%E7%B4%AF%E4%B9%97-an
int mod = MODA;
struct modint {
  ll x;
  modint(ll x) : x(x % mod) {}
  modint &operator+=(const modint a) {
    (x += a.x) %= mod;
    return *this;
  }
  modint &operator-=(const modint a) {
    (x -= a.x) %= mod;
    if (x < 0)
      x += mod;
    return *this;
  }
  modint &operator*=(const modint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  modint &operator/=(modint a) {
    ll exp = mod - 2;
    while (exp > 0) {
      if (exp & 1)
        *this *= a.x;
      a *= a.x;
      exp >>= 1;
    }
    return *this;
  }
  modint operator+(const modint a) const {
    modint res(*this);
    return res += a;
  }
  modint operator-(const modint a) const {
    modint res(*this);
    return res -= a;
  }
  modint operator*(const modint a) const {
    modint res(*this);
    return res *= a;
  }
  modint operator/(const modint a) const {
    modint res(*this);
    return res /= a;
  }
};
modint modpow(modint x, ll n) {
  modint res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x.x;
    x = x * x;
    n >>= 1;
  }
  return res;
}

int main() {
  int ans = 0;
  int tmp;
  int n, s;
  cin >> n >> s;
  vector<modint> dp;
  REP(i, 6001) dp.push_back(0);
  dp[0] = modpow((ll)2, n);
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  ll inv = MODA - 1 * (MODA / 2) % MODA;
  REP(j, n) {
    for (int i = s; i >= 0; i--) {
      if (dp[i].x > 0 && i + a[j] <= s)
        dp[i + a[j]] += dp[i] * inv;
    }
  }
  cout << dp[s].x << endl;
}

Error: TLE

Fixed submission:

// 高知能系Vtuberの高井茅乃です。
// Twitter: https://twitter.com/takaichino
// YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i, n) for (int i = 0; i < n; i++)
#define REP1(i, n) for (int i = 1; i <= n; i++)
#define MODA 998244353

// つねに10億7などの剰余をとる構造体
// 参考: https://www.youtube.com/watch?v=L8grWxBlIZ4&t=9858
// 参考:
// https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a#4-%E7%B4%AF%E4%B9%97-an
int mod = MODA;
struct modint {
  ll x;
  modint(ll x) : x(x % mod) {}
  modint &operator+=(const modint a) {
    (x += a.x) %= mod;
    return *this;
  }
  modint &operator-=(const modint a) {
    (x -= a.x) %= mod;
    if (x < 0)
      x += mod;
    return *this;
  }
  modint &operator*=(const modint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  modint &operator/=(modint a) {
    ll exp = mod - 2;
    while (exp > 0) {
      if (exp & 1)
        *this *= a.x;
      a *= a.x;
      exp >>= 1;
    }
    return *this;
  }
  modint operator+(const modint a) const {
    modint res(*this);
    return res += a;
  }
  modint operator-(const modint a) const {
    modint res(*this);
    return res -= a;
  }
  modint operator*(const modint a) const {
    modint res(*this);
    return res *= a;
  }
  modint operator/(const modint a) const {
    modint res(*this);
    return res /= a;
  }
};
modint modpow(modint x, ll n) {
  modint res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x.x;
    x = x * x;
    n >>= 1;
  }
  return res;
}

int main() {
  int ans = 0;
  int tmp;
  int n, s;
  cin >> n >> s;
  vector<modint> dp;
  REP(i, 6001) dp.push_back(0);
  dp[0] = modpow((ll)2, n);
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  REP(j, n) {
    for (int i = s; i >= 0; i--) {
      if (dp[i].x > 0 && i + a[j] <= s)
        dp[i + a[j]] += dp[i] / 2;
    }
  }
  cout << dp[s].x << endl;
}