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

#include <bits/stdc++.h>

const int INF = 1e9;
const int MOD = 998244353;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

ll powmod(ll n, ll x) {
  vector<ll> vll(32);
  vll[0] = n;
  FOR(i, 1, 32) { vll[i] = (vll[i - 1] * vll[i - 1]) % MOD; }
  ll ret = 1;
  int cnt = 0;
  while (x > 0) {
    if (x & 1) {
      ret = (ret * vll[cnt]) % MOD;
    }
    x >>= 1;
    cnt++;
  }
  return ret;
}

int main() {
  int n, s;
  cin >> n >> s;
  vector<int> vi(n);
  REP(i, n)
  cin >> vi[i];
  vector<vector<int>> dp(n + 1, vector<int>(s + 1, 0));
  dp[0][0] = 1;
  FOR(i, 1, n + 1) {
    REP(j, s + 1) {
      dp[i][j] = (dp[i][j] + ((dp[i - 1][j] * 2) % MOD)) % MOD;

      if (j + vi[i - 1] <= s)
        dp[i][j + vi[i - 1]] = (dp[i][j + vi[i - 1]] + dp[i - 1][j]) % MOD;
    }
  }

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

const int INF = 1e9;
const int MOD = 998244353;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

ll powmod(ll n, ll x) {
  vector<ll> vll(32);
  vll[0] = n;
  FOR(i, 1, 32) { vll[i] = (vll[i - 1] * vll[i - 1]) % MOD; }
  ll ret = 1;
  int cnt = 0;
  while (x > 0) {
    if (x & 1) {
      ret = (ret * vll[cnt]) % MOD;
    }
    x >>= 1;
    cnt++;
  }
  return ret;
}

int main() {
  int n, s;
  cin >> n >> s;
  vector<int> vi(n);
  REP(i, n)
  cin >> vi[i];
  sort(ALL(vi));
  map<pair<int, int>, int> mpii; // sum,use num
  vector<int> num(n, 0);
  mpii[{0, 0}] = 1;
  REP(i, n) {
    map<pair<int, int>, int> nextmpii;
    for (auto itr = mpii.begin(); itr != mpii.end(); itr++) {
      if ((itr->first).first + vi[i] > s) {
        continue;
      }
      nextmpii[{(itr->first).first, (itr->first).second}] += itr->second;
      if ((itr->first).first + vi[i] == s) {
        num[(itr->first).second] += itr->second;
      }
      if ((itr->first).first + vi[i] < s) {
        nextmpii[{(itr->first).first + vi[i], (itr->first).second + 1}] +=
            itr->second;
      }
    }
    mpii = nextmpii;
  }
  ll ans = 0;
  REP(i, n) { ans = (ans + (powmod(2, n - i - 1) * num[i]) % MOD) % MOD; }
  cout << ans << endl;
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fast_io()                                                              \\
  ios_base ::sync_with_stdio(0);                                               \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
using namespace std;
const int N = 3e3 + 7;
const int MOD = 998244353;
int n, s;
int dp[N][N];
int a[N];
int binpow(int a, int b) {
  a %= MOD;
  int res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}
int add(int x, int y) {
  int res = ((x % MOD) + (y % MOD)) % MOD;
  return res;
}
int mul(int x, int y) {
  int res = ((x % MOD) * (y % MOD)) % MOD;
  return res;
}
int32_t main() {
  fast_io();
  cin >> n >> s;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= s; j++)
      dp[i][j] = 0;
  }
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  dp[0][0] = binpow(2LL, n);
  int inv2 = binpow(2LL, MOD - 2);
  // for (int i = 1; i <= n; i++)
  // 	dp[i][a[i]] = 1;
  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]) {
        dp[i][j] = add(dp[i][j], mul(dp[i - 1][j - a[i]], inv2));
      }
    }
  }
  cout << dp[n][s] << "\\n";
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fast_io()                                                              \\
  ios_base ::sync_with_stdio(0);                                               \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
using namespace std;
const int N = 1e3 + 7;
const int MOD = 998244353;
int n, s;
int dp[N][N];
int a[N];
int binpow(int a, int b) {
  a %= MOD;
  int res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}
int add(int x, int y) {
  int res = ((x % MOD) + (y % MOD)) % MOD;
  return res;
}
int mul(int x, int y) {
  int res = ((x % MOD) * (y % MOD)) % MOD;
  return res;
}
int32_t main() {
  fast_io();
  cin >> n >> s;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= s; j++)
      dp[i][j] = 0;
  }
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  dp[0][0] = binpow(2LL, n);
  int inv2 = binpow(2LL, MOD - 2);
  // for (int i = 1; i <= n; i++)
  // 	dp[i][a[i]] = 1;
  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]) {
        dp[i][j] += mul(dp[i - 1][j - a[i]], inv2);
      }
    }
  }
  cout << dp[n][s] << "\\n";
  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define rep(i, x, n) for (int i = x; i <= n; i++)
#define per(i, n, x) for (int i = n; i >= x; i--)
#define sz(a) int(a.size())
#define rson mid + 1, r, p << 1 | 1
#define pii pair<int, int>
#define lson l, mid, p << 1
#define ll long long
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
const double eps = 1e-8;
const int mod = 998244353;
const int N = 1e5 + 10;
const int inf = 1e9;
int n, s, a[3010];
ll f[3010][3010];
ll x[3010];
int main() {
  // ios::sync_with_stdio(false);
  // freopen("in","r",stdin);
  x[0] = 1;
  rep(i, 1, 3000) x[i] = x[i - 1] * 2 % mod;
  cin >> n >> s;
  rep(i, 1, n) cin >> a[i];
  f[0][0] = 1;
  rep(i, 1, n) {
    rep(j, a[i], s) { f[i][j] = (f[i][j] + f[i - 1][j - a[i]]) % mod; }
    rep(j, 0, s) { f[i][j] = (f[i][j] + f[i - 1][j] * 2) % mod; }
  }
  cout << f[n][s] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define rep(i, x, n) for (int i = x; i <= n; i++)
#define per(i, n, x) for (int i = n; i >= x; i--)
#define sz(a) int(a.size())
#define rson mid + 1, r, p << 1 | 1
#define pii pair<int, int>
#define lson l, mid, p << 1
#define ll long long
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
const double eps = 1e-8;
const int mod = 998244353;
const int N = 1e5 + 10;
const int inf = 1e9;
int n, s, a[3010];
map<int, ll> f[3010];
ll x[3010];
int main() {
  // ios::sync_with_stdio(false);
  // freopen("in","r",stdin);
  x[0] = 1;
  rep(i, 1, 3000) x[i] = x[i - 1] * 2 % mod;
  cin >> n >> s;
  rep(i, 1, n) cin >> a[i];
  f[0][0] = 1;
  rep(i, 1, n) {
    per(j, s, a[i]) {
      for (auto it : f[j - a[i]]) {
        (f[j][it.fi + 1] += it.se) %= mod;
      }
    }
  }
  ll ans = 0;
  for (auto it : f[s])
    ans = (ans + it.se * x[n - it.fi] % mod) % mod;
  cout << ans << endl;
  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>

using s32 = int;
using u32 = unsigned int;
using s64 = long long int;
using u64 = unsigned long long int;

u32 n, s;
u32 A[200000];

constexpr u32 mod = 998244353;

u32 modpow(u32 a, int n) {
  u32 r = 1;
  for (; n; n >>= 1) {
    if (n & 1)
      r = (u64)r * a % mod;
    a = (u64)a * a % mod;
  }
  return r;
}

u32 dp[200001];

int main() {
  scanf("%d%d", &n, &s);
  for (int i = 0; i < n; ++i)
    scanf("%d", A + i);

  dp[0] = 1;
  for (u32 i = 0; i < n; ++i) {
    for (int j = s; j >= 0; --j) {
      dp[j] = (2 * dp[j] + (j >= A[i] ? dp[j - A[i]] : 0)) % mod;
    }
  }

  printf("%d\\n", (u32)dp[s]);

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>

using s32 = int;
using u32 = unsigned int;
using s64 = long long int;
using u64 = unsigned long long int;

u32 n, s;
u32 A[200000];

constexpr u32 mod = 998244353;
constexpr u32 root = 3;
// constexpr u32 randomn = 7 * 17 * (1 << 5);
// constexpr u32 randomn = 17 * (1 << 9);
// constexpr u32 randomn = 7 * (1 << 21);
constexpr u32 randomn = 7 * (1 << 16);

u32 modpow(u32 a, int n) {
  u32 r = 1;
  for (; n; n >>= 1) {
    if (n & 1)
      r = (u64)r * a % mod;
    a = (u64)a * a % mod;
  }
  return r;
}

u32 div2(u32 a) {
  if (a & 1)
    a += mod;
  return a / 2;
}

int main() {
  scanf("%d%d", &n, &s);
  for (int i = 0; i < n; ++i)
    scanf("%d", A + i);

  u32 g = modpow(root, (mod - 1) / randomn);
  u64 ans = 0;
  for (int i = 0; i < randomn; ++i) {
    u64 r = 1;
    u32 gg = modpow(g, i);
    for (int j = 0; j < n; ++j) {
      r = r * (2 + modpow(gg, A[j])) % mod;
    }
    r = r * modpow(gg, mod - 1 - s) % mod;
    ans += r;
  }
  ans %= mod;
  ans = ans * modpow(randomn, mod - 2) % mod;
  printf("%d\\n", (u32)ans);

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

#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define fi first
#define se second
#define mp make_pair
using ll = long long;

ll power(ll n, ll m) {
  ll ans = 1;
  for (int r = 0; m >> r > 0; r++) {
    if ((m >> r) & 1)
      ans = ans * n % mod;
    n = n * n % mod;
  }
  return ans;
}

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

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define fi first
#define se second
#define mp make_pair
using Graph = vector<vector<vector<pair<int, int>>>>;
using ll = long long;

ll power(ll n, ll m) {
  ll ans = 1;
  for (int r = 0; m >> r > 0; r++) {
    if ((m >> r) & 1)
      ans = ans * n % mod;
    n = n * n % mod;
  }
  return ans;
}

int main() {
  int N, S;
  cin >> N >> S;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  Graph dp(N + 1, vector<vector<pair<int, int>>>(
                      S + 1)); // 第一要素サイズ、第二要素個数
  dp[0][0].push_back(mp(0, 1));
  for (int i = 1; i < N + 1; i++) {
    for (int j = 0; j < S + 1; j++) {
      if (j - A[i - 1] >= 0) {
        for (int k = 0; k < dp[i - 1][j - A[i - 1]].size(); k++) {
          pair<int, int> p = dp[i - 1][j - A[i - 1]][k];
          p.fi++;
          dp[i][j].push_back(p);
        }
      }
      for (int k = 0; k < dp[i - 1][j].size(); k++) {
        dp[i][j].push_back(dp[i - 1][j][k]);
      }
    }
  }
  ll ans = 0;
  for (int k = 0; k < dp[N][S].size(); k++) {
    pair<int, int> p = dp[N][S][k];
    // cout << p.first << endl;
    ans = (ans + p.se * power(2, N - p.first)) % mod;
  }
  cout << ans << endl;
  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> mp;
ll inf = 1e9;
ll mod = 998244353;

int main() {
  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 + 1, vector<ll>(s + 1, 0));
  dp[0][0] = 1;
  // map<mp,ll> dp;
  // dp[mp(0,0)] = 1;
  // vector<ll> beki(n+1,1);
  // for(ll i=1;i<=n;i++) beki[i] = (beki[i-1]*2)%mod;

  /*for(ll j=0;j<n;j++){
   map<mp,ll> tmp=dp;
   for(auto i:tmp){
    ll cnt = i.first.second+1;
    ll value = i.first.first + a[j];
    ll c = i.second;
    if(value <= s ){
     dp[ mp(value,cnt) ]+=i.second;
     dp[ mp(value,cnt) ]%=mod;
    }
   }
  }

  ll ans = 0;
  for(auto i:dp){
   ll cnt = i.first.second;
   ll value = i.first.first;
   if( value == s ){
    ans += (beki[n-cnt]*i.second)%mod;
    ans %= mod;
   }
  }*/
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j <= s; j++)
      dp[i + 1][j] += (2 * dp[i][j]) % mod, dp[i + 1][j] %= mod;
    for (ll j = a[i]; j <= s; j++)
      dp[i + 1][j] += dp[i][j - a[i]], dp[i + 1][j] %= mod;
  }
  ll ans = 0;
  cout << dp[n][s] << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> mp;
ll inf = 1e9;
ll mod = 998244353;

int main() {
  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+1,vector<ll>(s+1,0) );
  // dp[0][0] = 1;
  map<mp, ll> dp;
  dp[mp(0, 0)] = 1;
  vector<ll> beki(n + 1, 1);
  for (ll i = 1; i <= n; i++)
    beki[i] = (beki[i - 1] * 2) % mod;

  for (ll j = 0; j < n; j++) {
    map<mp, ll> tmp = dp;
    for (auto i : tmp) {
      ll cnt = i.first.second + 1;
      ll value = i.first.first + a[j];
      ll c = i.second;
      if (value <= s) {
        dp[mp(value, cnt)] += i.second;
        dp[mp(value, cnt)] %= mod;
      }
    }
  }

  ll ans = 0;
  for (auto i : dp) {
    ll cnt = i.first.second;
    ll value = i.first.first;
    if (value == s) {
      ans += (beki[n - cnt] * i.second) % mod;
      ans %= mod;
    }
  }
  cout << ans << endl;

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

//  Copyright © 2020 Diego Garcia Rodriguez del Campo. All rights reserved.
#include <bits/stdc++.h>
#define MAX 3005
#define optimiza_io                                                            \\
  cin.tie(0);                                                                  \\
  ios_base::sync_with_stdio(0);
#define what_is(x) cerr << #x << " is " << x << endl;
#define pii pair<ll, ll>
#define fi first
#define se second
using namespace std;
typedef long long ll;

ll a[MAX], N, S, ans;
ll memo[MAX][MAX];
const ll MOD = 998244353;

ll dp(ll x, ll sm) {
  if (x > N) {
    if (sm != S)
      return 0;
    return 1;
  }
  if (sm > S)
    return 0;
  if (memo[x][sm] != -1)
    return memo[x][sm];

  ll ans = 0;
  ans += dp(x + 1, sm + a[x]);
  ans += dp(x + 1, sm) * 2;
  ans %= MOD;
  return memo[x][sm] = ans;
}

int main() {
  optimiza_io cin >> N >> S;
  for (ll i = 1; i <= N; i++)
    cin >> a[i];
  memset(memo, -1, sizeof memo);
  cout << dp(1, 0) << "\\n";
  return 0;
}

// CHECAR LIMITES

Error: 0

Fixed submission:

//  Copyright © 2020 Diego Garcia Rodriguez del Campo. All rights reserved.
#include <bits/stdc++.h>
#define MAX 3005
#define optimiza_io                                                            \\
  cin.tie(0);                                                                  \\
  ios_base::sync_with_stdio(0);
#define what_is(x) cerr << #x << " is " << x << endl;
#define pii pair<ll, ll>
#define fi first
#define se second
using namespace std;
typedef long long ll;

ll a[MAX], N, S, ans;
ll memo[MAX][MAX];
const ll MOD = 998244353;

ll dp(ll x, ll sm) {
  if (x > N) {
    if (sm != S)
      return 0;
    return 1;
  }
  if (memo[x][sm] != -1)
    return memo[x][sm];

  ll ans = 0;
  ans += dp(x + 1, sm + a[x]);
  ans += dp(x + 1, sm) * 2;
  ans %= MOD;
  return memo[x][sm] = ans;
}

int main() {
  optimiza_io cin >> N >> S;
  for (ll i = 1; i <= N; i++)
    cin >> a[i];
  memset(memo, -1, sizeof memo);
  cout << dp(1, 0) << "\\n";
  return 0;
}

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

#include <algorithm>
#include <array>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
constexpr long long int MOD = 998244353;
constexpr long long int power(const long long int base, const int exp) {
  switch (exp) {
  case 0:
    return 1LL;
  case 1:
    return base % MOD;
  default:
    return power(base * base % MOD, exp >> 1) * power(base, exp & 1) % MOD;
  }
}
int main() {
  int n, s;
  std::cin >> n >> s;
  std::vector<int> nums(n);
  for (auto &a : nums)
    std::cin >> a;
  std::vector<long long int> memo(s + 1, 0);
  memo[0] = power(2, n);
  constexpr long long int inv_2 = power(2, MOD - 2);
  for (const auto a : nums) {
    for (auto sum = s; sum >= a; --sum) {
      memo[sum] += memo[sum - a] * inv_2 % MOD;
      memo[sum] %= MOD;
    }
  }
  std::cout << memo.back() << '\\n';
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <array>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
constexpr long long int MOD = 998244353;
long long int power(const long long int base, const int exp) {
  switch (exp) {
  case 0:
    return 1LL;
  case 1:
    return base % MOD;
  default:
    return power(base * base % MOD, exp >> 1) * power(base, exp & 1) % MOD;
  }
}
int main() {
  int n, s;
  std::cin >> n >> s;
  std::vector<int> nums(n);
  for (auto &a : nums)
    std::cin >> a;
  std::vector<std::vector<long long int>> memo(
      n + 1, std::vector<long long int>(s + 1, 0));
  memo[0][0] = 1;
  for (const auto a : nums) {
    for (int c = n; c >= 1; --c) {
      for (auto sum = s; sum >= a; --sum) {
        memo[c][sum] += memo[c - 1][sum - a];
        memo[c][sum] %= MOD;
      }
    }
  }
  long long int result{0};
  for (auto count = 1; count <= n; ++count) {
    result += memo[count].back() * power(2, n - count) % MOD;
    result %= MOD;
  }
  std::cout << result << '\\n';
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, s;
ll a[3003], dp[6003];
const ll mod = 998244353;
int main(void) {
  scanf("%lld%lld", &n, &s);
  for (ll i = 0; i < n; i++)
    scanf("%lld", &a[i]);
  dp[0] = 1;
  for (ll i = 0; i < n; i++) {
    for (ll j = s; j >= 0; j--) {
      dp[j + a[i]] += dp[j];
      dp[j + a[i]] %= mod;
      dp[j] *= 2;
      dp[j] %= mod;
    }
  }
  printf("%lld", dp[s]);
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, s;
ll a[3003], dp[3003];
const ll mod = 998244353;
int main(void) {
  scanf("%lld%lld", &n, &s);
  for (ll i = 0; i < n; i++)
    scanf("%lld", &a[i]);
  dp[0] = 1;
  for (ll i = 0; i < n; i++) {
    for (ll j = s; j >= 0; j--) {
      dp[j + a[i]] += dp[j];
      dp[j + a[i]] %= mod;
      dp[j] *= 2;
      dp[j] %= mod;
    }
  }
  printf("%lld", dp[s]);
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define MAX (ll)(3e3 + 7)
#define INF (ll)(4e18)
#define MOD (ll)(998244353)

using namespace std;
using ll = long long;
using cd = complex<double>;

int dp[MAX][MAX];
int mult(int a, int b) { return (a * 1LL * b) % MOD; }

int add(int a, int b) { return (a + b) % MOD; }

int pw(int a, int b) {
  int r = 1;
  while (b) {
    if (b & 1) {
      r = mult(r, a);
    }
    b >>= 1;
    a = mult(a, a);
  }
  return r;
}

int main() {
  int n, s;
  cin >> n >> s;
  int ar[n];
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  dp[0][0] = pw(2, n);
  int div = pw(2, MOD - 2);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= s; j++) {
      dp[i + 1][j] = add(dp[i + 1][j], dp[i][j]);
      if (ar[i] + j <= s) {
        dp[i + 1][ar[i] + j] = add(dp[i + 1][ar[i] + j], mult(dp[i][j], div));
      }
    }
  }
  cout << dp[n][s] << "\\n";
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define MAX (ll)(1e3 + 7)
#define INF (ll)(4e18)
#define MOD (ll)(998244353)

using namespace std;
using ll = long long;
using cd = complex<double>;

int dp[MAX][MAX];
int mult(int a, int b) { return (a * 1LL * b) % MOD; }

int add(int a, int b) { return (a + b) % MOD; }

int pw(int a, int b) {
  int r = 1;
  while (b) {
    if (b & 1) {
      r = mult(r, a);
    }
    b >>= 1;
    a = mult(a, a);
  }
  return r;
}

int main() {
  int n, s;
  cin >> n >> s;
  int ar[n];
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  dp[0][0] = pw(2, n);
  int div = pw(2, MOD - 2);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= s; j++) {
      dp[i + 1][j] = add(dp[i + 1][j], dp[i][j]);
      if (ar[i] + j <= s) {
        dp[i + 1][ar[i] + j] = add(dp[i + 1][ar[i] + j], mult(dp[i][j], div));
      }
    }
  }
  cout << dp[n][s] << "\\n";
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const i64 MOD = 998244353;

int main() {
  i64 N, S;
  cin >> N >> S;
  vector<i64> A(N);
  for (i64 i = 0; i < N; i++)
    cin >> A[i];
  vector<vector<i64>> dp(N + 1, vector<i64>(S + 1));
  dp[0][0] = 1;
  for (i64 i = 0; i < N; i++) {
    for (i64 j = 0; j <= S; j++)
      (dp[i + 1][j] = dp[i][j] * 2) %= MOD;
    for (i64 j = 0; j <= S - A[i]; j++)
      (dp[i + 1][j + A[i]] += dp[i][j]) %= MOD;
  }
  cout << dp[N][S] << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
using i64 = long long;
#define endl "\\n"

const i64 MOD = 998244353;

int main() {
  i64 N, S;
  cin >> N >> S;
  vector<i64> A(N);
  for (i64 i = 0; i < N; i++)
    cin >> A[i];
  vector<vector<vector<i64>>> dp(
      N + 1, vector<vector<i64>>(N + 1, vector<i64>(S + 1)));
  dp[0][0][0] = 1;
  for (i64 i = 0; i < N; i++)
    for (i64 j = 0; j <= i; j++)
      for (i64 k = 0; k <= S; k++) {
        if (k + A[i] <= S)
          (dp[i + 1][j + 1][k + A[i]] += dp[i][j][k]) %= MOD;
        (dp[i + 1][j][k] += dp[i][j][k]) %= MOD;
      }
  vector<i64> m(N);
  m[0] = 1;
  for (i64 i = 0; i < N - 1; i++)
    (m[i + 1] = m[i] * 2) %= MOD;
  i64 ans = 0;
  for (i64 i = 0; i <= N; i++)
    (ans += dp[N][i][S] * m[N - i]) %= MOD;
  cout << ans << endl;
  return 0;
}