alexjercan/bugnet huggingface dataset:
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s;
  cin >> n >> s;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  long long mod = 998244353LL;
  long long dp[n + 1][s + 1];
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= s; j++)
      dp[i][j] = 0LL;
  dp[0][0] = 1LL;
  for (int i = 0; i < n; i++)
    for (int j = 0; j <= s; j++) {
      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: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s;
  cin >> n >> s;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  long long mod = 998244353LL;
  long long dp[s + 1][n + 1];
  for (int i = 0; i <= s; i++)
    for (int j = 0; j <= n; j++)
      dp[i][j] = 0LL;
  for (int i = 0; i < n; i++)
    for (int j = 0; j <= s; j++) {
      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;
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

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

const long long MOD = 998244353;

long long pow(long long x, long long n, long long mod) {
  long long ans = 1;
  while (n) {
    if (n % 2)
      ans *= x;
    x *= x;
    x %= mod;
    ans %= mod;
    n >>= 1;
  }
  return ans;
}

long long inv = pow(2, MOD - 2, MOD);

long long dp[3010][3010];

void solve(long long N, long long S, std::vector<long long> A) {
  dp[0][0] = pow(2, N, MOD);
  if (A[0] <= S) {
    dp[0][A[0]] = pow(2, N - 1, MOD);
  }

  for (int i = 1; i < N; i++) {
    for (int j = 0; j <= S; j++) {
      dp[i][j] += dp[i - 1][j];
      if (j - A[i] >= 0) {
        dp[i][j] += dp[i - 1][j - A[i]] * inv;
      }
      dp[i][j] %= MOD;
    }
  }

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

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  long long N;
  scanf("%lld", &N);
  long long S;
  scanf("%lld", &S);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, S, std::move(A));
  return 0;
}


Error: 0

Fixed submission:

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

const long long MOD = 998244353;

long long pow(long long x, long long n, long long mod) {
  long long ans = 1;
  while (n) {
    if (n % 2)
      ans *= x;
    x *= x;
    x %= mod;
    ans %= mod;
    n >>= 1;
  }
  return ans;
}

long long inv = pow(2, MOD - 2, MOD);

long long dp[3010][3010];

void solve(long long N, long long S, std::vector<long long> A) {
  dp[0][0] = pow(2, N, MOD);
  if (A[0] <= S) {
    dp[0][A[0]] = pow(2, N - 1, MOD);
  }

  for (int i = 1; i < N; i++) {
    for (size_t j = 0; j <= S; j++) {
      dp[i][j] += dp[i - 1][j];
      if (j - A[i] >= 0) {
        dp[i][j] += dp[i - 1][j - A[i]] * inv;
      }
      dp[i][j] %= MOD;
    }
  }

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

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  long long N;
  scanf("%lld", &N);
  long long S;
  scanf("%lld", &S);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, S, std::move(A));
  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 3e3 + 5;
const int INF = 0x7f7f7f7f;
const ll p = 998244353;
#define DEBUG(x) cout << x << '\\n'

int n, s, t, f[MAXN];
ll f_pow(ll a, ll b) {
  ll res = 1;
  for (; b; b >>= 1, a = a * a % p)
    if (b & 1)
      res = res * a % p;
  return res;
}
int main() {
#ifdef Irene
  freopen("in.txt", "r", stdin);
#endif // Irene
  ios::sync_with_stdio(false);

  cin >> n >> s;
  f[0] = f_pow(2, n);
  ll inv2 = f_pow(2, p - 2);
  for (int i = 1; i <= n; i++) {
    cin >> t;
    for (int j = s - t; j >= 0; j--)
      f[j + t] = (f[j + t] + f[j] * inv2) % p;
  }
  cout << f[s];
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 3e3 + 5;
const int INF = 0x7f7f7f7f;
const ll p = 998244353;
#define DEBUG(x) cout << x << '\\n'

int n, s, t, f[MAXN];
ll f_pow(ll a, ll b) {
  ll res = 1;
  for (; b; b >>= 1, a = a * a % p)
    if (b & 1)
      res = res * a % p;
  return res;
}
int main() {
#ifdef Irene
  freopen("in.txt", "r", stdin);
#endif // Irene
  ios::sync_with_stdio(false);

  cin >> n >> s;
  f[0] = f_pow(2, n);
  ll inv2 = f_pow(2, p - 2);
  for (int i = 1; i <= n; i++) {
    cin >> t;
    for (int j = s - t; ~j; j--)
      f[j + t] = (f[j + t] + f[j] * inv2) % p;
  }
  cout << f[s];
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 3010;
const int mod = 998244353;
int n, s;
ll arr[N], dp[N][N];
bool vis[N][N];

ll fun(int pos, int rem) {
  if (pos > n) {
    if (rem == 0)
      return 1;
    return 0;
  }
  ll &ret = dp[pos][rem];
  if (vis[pos][rem])
    return ret;
  vis[pos][rem] = true;
  ret = 0;
  if (rem >= arr[pos]) {
    ret = (ret + fun(pos + 1, rem - arr[pos])) % mod;
  }
  ret = (ret + 2LL * fun(pos + 1, rem)) % mod;
  return ret;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> s;
  for (int i = 1; i <= n; ++i)
    cin >> arr[i];
  cout << fun(1, s) << '\\n';
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 3010;
const int mod = 998244353;
int n, s;
ll arr[N], dp[N][N];
bool vis[N][N];

ll fun(int pos, int rem) {
  if (pos > n) {
    if (rem == 0)
      return 1;
    return 0;
  }
  ll &ret = dp[pos][rem];
  if (vis[pos][rem])
    return ret;
  ret = 0;
  if (rem >= arr[pos]) {
    ret = (ret + fun(pos + 1, rem - arr[pos])) % mod;
  }
  ret = (ret + 2LL * fun(pos + 1, rem)) % mod;
  return ret;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> s;
  for (int i = 1; i <= n; ++i)
    cin >> arr[i];
  cout << fun(1, s) << '\\n';
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vc = vector<char>;
using vvc = vector<vc>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep2(i, s, n) for (int i = (s); i < (int)n; i++)
int INF = 1e9 + 7, MOD = 998244353;

int main() {
  int N, S;
  cin >> N >> S;
  vi A(N);
  rep(i, N) cin >> A[i];

  vvi dp(N + 1, vi(S + 1));
  dp[0][0] = 1;
  rep(i, N) {
    rep(j, S + 1) {
      dp[i + 1][j] = dp[i][j] * 2 % MOD;
      if (j >= A[i])
        dp[i + 1][j] = (dp[i + 1][j] + dp[i][j - A[i]]) % MOD;
    }
  }

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep2(i, s, n) for (int i = (s); i < (int)n; i++)
int INF = 1e9 + 7;
int MOD = 998244353;

ll power(ll a, int b) {
  if (!b)
    return 1;
  ll c = power(a, b / 2);
  if (b % 2)
    return c * c % MOD * a % MOD;
  return c * c % MOD;
}

int main() {
  int N, S;
  cin >> N >> S;
  vi A(N);
  rep(i, N) cin >> A[i];

  vector<vvi> dp(N + 1, vvi(S + 1));
  sort(A.begin(), A.end());
  dp[0][0] = vi(1);
  rep(i, N) {
    rep(j, A[i]) dp[i + 1][j] = dp[i][j];
    rep2(j, A[i], S + 1) {
      dp[i + 1][j] = dp[i][j];
      if (dp[i][j - A[i]].size()) {
        for (int x : dp[i][j - A[i]])
          dp[i + 1][j].push_back(x + 1);
      }
    }
  }

  ll ans = 0;
  for (int x : dp[N][S])
    ans = (ans + power(2, N - x)) % MOD;

  cout << ans << endl;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> vi;
// #define endl '\\n'
#define fo(i, a, b) for (int i = a; i <= b; i++)
#define rf(i, a, b) for (int i = a; i >= b; i--)
#define fast_io ios_base::sync_with_stdio(0);
#define show(x) cout << x << endl;
#define pret(x)                                                                \\
  cout << x << endl;                                                           \\
  return 0;
#define disp(x) cout << x << " ";
#define let(x, y) cout << x << " " << y << endl;
ll MOD = 998244353;
const int maxn = 3e3 + 5;

int dp[maxn][maxn];

int32_t main() {
  fast_io;
  int n, s;
  cin >> n >> s;
  int a[n + 1];
  for (int i = 0; i < n; ++i) {
    cin >> a[i + 1];
  }
  dp[0][0] = 1;
  fo(i, 1, n) {
    for (int j = 0; j + a[i] < maxn; ++j) {
      dp[i][j + a[i]] = dp[i - 1][j];
    }
    for (int j = 0; j < maxn; ++j) {
      dp[i][j] = (dp[i][j] + 2 * dp[i - 1][j]) % MOD;
    }
  }
  show(dp[n][s]);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define endl '\\n'
#define fo(i, a, b) for (int i = a; i <= b; i++)
#define rf(i, a, b) for (int i = a; i >= b; i--)
#define fast_io ios_base::sync_with_stdio(0);
#define show(x) cout << x << endl;
#define pret(x)                                                                \\
  cout << x << endl;                                                           \\
  return 0;
#define disp(x) cout << x << " ";
#define let(x, y) cout << x << " " << y << endl;
ll MOD = 998244353;
const int maxn = 3e3 + 5;

int p[maxn];
unordered_map<int, ll> m[maxn];

int32_t main() {
  fast_io;
  int n, s;
  int tot = 0;
  cin >> n >> s;
  tot = n;
  vector<int> a;
  p[0] = 1;
  fo(i, 1, maxn - 1) { p[i] = (p[i - 1] * 2ll) % MOD; }
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    if (x <= s)
      a.emplace_back(x);
  }
  n = a.size();
  set<pair<int, ll>> st;
  ll ans = 0;
  st.insert({0, 1});
  m[0][0] = 1;
  for (int i = 0; i < n; ++i) {
    rf(j, i, 0) {
      for (const auto &it : m[j]) {
        m[j + 1][it.first + a[i]] += it.second;
      }
    }
  }
  fo(i, 1, s) { ans = (ans + m[i][s] * p[tot - i]) % MOD; }
  show(ans);
  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
#define lli long long int
lli MOD = 998244353;
lli powa(lli x, lli y) {
  lli ans = 1;
  lli m = MOD;
  while (y > 0) {
    if (y % 2 == 1) {
      ans *= x;
      ans %= m;
    }
    y /= 2;
    x = x * x;
    x %= m;
  }
  return ans % m;
}
lli a[3005];
lli dp[3004][3004];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  lli n, s;
  cin >> n >> s;
  for (int i = 0; i < n; i++)
    cin >> a[i + 1];
  dp[0][0] = powa(2, n);
  lli inv = powa(2, MOD - 2);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= s; j++) {
      dp[i + 1][j] += dp[i][j];
      dp[i + 1][j] %= MOD;
      if (j + a[i + 1] <= s) {
        dp[i + 1][j + a[i + 1]] += dp[i][j] * inv;
        dp[i + 1][j + a[i + 1]] %= MOD;
      }
    }
  }
  cout << dp[n][s];
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
#define lli long long int
lli MOD = 998244353;
lli powa(lli x, lli y) {
  lli ans = 1;
  lli m = MOD;
  while (y > 0) {
    if (y % 2 == 1) {
      ans *= x;
      ans %= m;
    }
    y /= 2;
    x = x * x;
    x %= m;
  }
  return ans % m;
}
lli a[3005];
lli dp[3004][3004];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  lli n, s;
  cin >> n >> s;
  for (int i = 0; i < n; i++)
    cin >> a[i + 1];
  dp[0][0] = powa(2, n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= s; j++) {
      dp[i + 1][j] += dp[i][j];
      dp[i + 1][j] %= MOD;
      if (j + a[i + 1] <= s) {
        dp[i + 1][j + a[i + 1]] += dp[i][j] * powa(2, MOD - 2);
        dp[i + 1][j + a[i + 1]] %= MOD;
      }
    }
  }
  cout << dp[n][s];
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

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

signed main() {
  ll n, s;
  cin >> n >> s;
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
    scanf("%lld", &a[i]);
  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] += 2 * dp[i][j];
      dp[i + 1][j] %= MOD;
      if (j - a[i] >= 0)
        dp[i + 1][j] += dp[i][j - a[i]];
      dp[i + 1][j] %= MOD;
    }
  }
  cout << dp[n][s] << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998244353;
const int MAX = 3010;

void rec(const vector<vector<int>> &dp, const vector<int> &a, int i, int j,
         deque<int> &keiro, vector<deque<int>> &ans) {
  if (i == 0) {
    if (j == 0) {
      ans.push_back(keiro);
    }
    return;
  }

  // 上へ遡る (dp[i-1][j] == 0) だったら無視)
  if (dp[i - 1][j]) {
    rec(dp, a, i - 1, j, keiro, ans);
  }
  // 左上へ遡る (dp[i-1][j-a[i-1]] == 0 だったら無視)
  if (j - a[i - 1] >= 0 && dp[i - 1][j - a[i - 1]]) {
    keiro.push_front(a[i - 1]);
    rec(dp, a, i - 1, j - a[i - 1], keiro, ans);
    keiro.pop_front();
  }
}

int main() {
  ll N, X;
  cin >> N >> X;
  vector<int> a(N);
  for (int i = 0; i < N; ++i)
    scanf("%d", &a[i]);

  // DP
  vector<vector<int>> dp(N + 1, vector<int>(MAX, 0));
  dp[0][0] = 1;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < MAX; ++j) {
      dp[i + 1][j] += dp[i][j];
      dp[i + 1][j] %= MOD;
      if (j + a[i] < MAX) {
        dp[i + 1][j + a[i]] += dp[i][j];
        dp[i + 1][j + a[i]] %= MOD;
      }
    }
  }

  // 復元
  deque<int> keiro;
  vector<deque<int>> ans;
  rec(dp, a, N, X, keiro, ans);
  ll num = 0;
  // 出力
  // cout << "the num of combinations is: " << ans.size() << endl;
  for (int i = 0; i < ans.size(); ++i) {
    //  cout << i+1 << " case:";
    ll x = 1;
    for (int j = 0; j < N - ans[i].size(); j++)
      x *= 2LL, x %= MOD;
    num += x;
    num %= MOD;
  }
  cout << num << endl;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const int N = 3e3 + 3;
ll mem[N][N];
ll pow2[N];
ll ar[N];
ll ans = 0;
ll n, s;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  pow2[0] = 1;
  for (int i = 1; i < N; i++)
    pow2[i] = (pow2[i - 1] * 2ll) % MOD;
  cin >> n >> s;
  for (int i = 0; i < n; i++)
    cin >> ar[i];
  for (int i = 0; i < n; i++)
    mem[i][0] = 2;
  if (ar[0] <= s)
    mem[0][ar[0]] = 1;
  for (int i = 1; i < n; i++)
    for (int j = 0; j <= s; j++) {
      if (ar[i] <= j)
        mem[i][j] = ((2 * mem[i - 1][j]) + mem[i - 1][j - ar[i]]) % MOD;
      else
        mem[i][j] = (2 * mem[i - 1][j]) % MOD;
      //		cout << i << ' ' << j << " : " << mem[i][j] << '\\n';
    }
  cout << mem[n - 1][s] << '\\n';
}


Error: TLE

Fixed submission:

#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const int N = 3e3 + 3;
bool mem[N][N];
ll pow2[N];
ll ar[N];
ll ans = 0;
ll n, s;
void dp(int idx, int dep, int sum) {
  //	cout << idx << ' ' << dep << ' ' << sum << " : " << '\\n';
  if (idx == 0 && sum != 0 && mem[0][sum]) {
    //		cout << dep << '\\n';
    ans = (ans + pow2[n - dep - 1]) % MOD;
    return;
  }
  if (idx == 0 && sum == 0) {
    //		cout << dep << '\\n';
    ans = (ans + pow2[n - dep]) % MOD;
    return;
  }
  if (mem[idx - 1][sum])
    dp(idx - 1, dep, sum);
  if (sum >= ar[idx] && mem[idx - 1][sum - ar[idx]])
    dp(idx - 1, dep + 1, sum - ar[idx]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  pow2[0] = 1;
  for (int i = 1; i < N; i++)
    pow2[i] = (pow2[i - 1] * 2ll) % MOD;
  cin >> n >> s;
  for (int i = 0; i < n; i++)
    cin >> ar[i];
  for (int i = 0; i < n; i++)
    mem[i][0] = 1;
  if (ar[0] <= s)
    mem[0][ar[0]] = 1;
  for (int i = 1; i < n; i++)
    for (int j = 0; j <= s; j++)
      mem[i][j] =
          (ar[i] <= j) ? mem[i - 1][j] | mem[i - 1][j - ar[i]] : mem[i - 1][j];
  if (mem[n - 1][s] == 0)
    cout << "0\\n";
  else {
    dp(n - 1, 0, s);
    cout << ans << '\\n';
  }
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 3001;

int n, s, dp[N][N], mod = 998244353;
vector<int> a;

int solve(int idx, int sum) {
  if (sum > s)
    return 0;
  if (idx == n)
    return sum == s;
  int &ret = dp[idx][sum];
  if (ret != -1)
    return ret;
  ret = 2 * solve(idx + 1, sum);
  if (ret >= mod)
    ret -= mod;
  ret += solve(idx + 1, sum + a[idx]);
  if (ret >= mod)
    ret -= mod;
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  memset(dp, -1, sizeof dp);
  cin >> n >> s;
  a.resize(n);
  for (auto &i : a)
    cin >> i;
  cout << solve(0, 0) << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 2001;

int n, s, dp[N][N], mod = 998244353;
vector<int> a;

int solve(int idx, int sum) {
  if (sum > s)
    return 0;
  if (idx == n)
    return sum == s;
  int &ret = dp[idx][sum];
  if (ret != -1)
    return ret;
  ret = 2 * solve(idx + 1, sum);
  if (ret >= mod)
    ret -= mod;
  ret += solve(idx + 1, sum + a[idx]);
  if (ret >= mod)
    ;
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  memset(dp, -1, sizeof dp);
  cin >> n >> s;
  a.resize(n);
  for (auto &i : a)
    cin >> i;
  cout << solve(0, 0) << endl;
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

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

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template <class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

const ll mod = 998244353;

ll modpow(ll b, ll e) {
  ll ans = 1;
  for (; e; b = b * b % mod, e /= 2)
    if (e & 1)
      ans = ans * b % mod;
  return ans;
}

ll inv(ll x) { return modpow(x, mod - 2); }

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n, s;
  cin >> n >> s;
  vi a(n);
  rep(i, 0, n) cin >> a[i];

  ll i2 = inv(2);
  vi dp(s + 1, 0);
  dp[0] = 1;
  rep(i, 0, n) {
    per(j, 0, s) {
      if (j + a[i] <= s) {
        dp[j + a[i]] += dp[j] * i2 % mod;
        dp[j + a[i]] %= mod;
      }
    }
  }

  ll ans = modpow(2, n) * dp[s] % mod;
  ans %= mod;
  ans += mod;
  ans %= mod;

  cout << ans << '\\n';
}

Error: 0

Fixed submission:

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

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template <class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

const ll mod = 998244353;

ll modpow(ll b, ll e) {
  ll ans = 1;
  for (; e; b = b * b % mod, e /= 2)
    if (e & 1)
      ans = ans * b % mod;
  return ans;
}

ll inv(ll x) { return modpow(x, mod - 2); }

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n, s;
  cin >> n >> s;
  vi a(n);
  rep(i, 0, n) cin >> a[i];

  ll i2 = inv(2);
  vi dp(s + 1, 0);
  dp[0] = 1;
  rep(i, 0, n) {
    per(j, 0, 3000) {
      if (j + a[i] <= 3000) {
        dp[j + a[i]] += dp[j] * i2 % mod;
        dp[j + a[i]] %= mod;
      }
    }
  }

  ll ans = modpow(2, n) * dp[s] % mod;
  ans %= mod;
  ans += mod;
  ans %= mod;

  cout << ans << '\\n';
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Rep(i, n) for (int i = 1; i <= (n); ++i)
using LL = long long;
using ULL = unsigned long long;

const int mod = 998244353;
const double pi = acos(-1.0);
const double eps = 1e-6;

LL dp[3001][3001];

int main() {
  int n, s, a;
  cin >> n >> s;
  dp[0][0] = 1;
  Rep(i, n) {
    cin >> a;
    for (int j = s; j >= a; --j) {
      dp[i][j] += dp[i - 1][j - a];
    }
    rep(j, s + 1) dp[i][j] = (dp[i][j] + dp[i - 1][j] * 2) % mod;
  }
  LL ans = 0, base = 1;
  rep(i, n) {
    ans = (ans + base * dp[n - i][s]) % mod;
    base = base * 2 % mod;
  }
  cout << dp[n][s] << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Rep(i, n) for (int i = 1; i <= (n); ++i)
using LL = long long;
using ULL = unsigned long long;

const int mod = 998244353;
const double pi = acos(-1.0);
const double eps = 1e-6;

LL dp[3001][3001];

int main() {
  int n, s, a;
  cin >> n >> s;
  dp[0][0] = 1;
  Rep(k, n) {
    cin >> a;
    for (int i = k; i; --i) {
      for (int j = s; j >= a; --j) {
        dp[i][j] += dp[i - 1][j - a];
        if (dp[i][j] >= mod)
          dp[i][j] -= mod;
      }
    }
  }
  LL ans = 0, base = 1;
  rep(i, n) {
    ans = (ans + base * dp[n - i][s]) % mod;
    base = base * 2 % mod;
  }
  cout << ans << endl;
  return 0;
}