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

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define rrep1(i, n) for (int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 998244353
#define INF 1000000000000000LL

using namespace std;

#define MAXNS 3001
ll dp[MAXNS][MAXNS];

int main() {
  int n, s;
  cin >> n >> s;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  dp[0][0] = 1;
  rep(i, n) rep(j, s + 1) {
    ll cn = a[i];
    dp[i + 1][j] += dp[i][j] * 2;
    dp[i + 1][j] %= MOD;
    if (j + cn <= s) {
      dp[i + 1][j + cn] += dp[i][j];
      dp[i + 1][j + cn] %= MOD;
    }
  }

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

  return 0;

  rep(i, n + 1) {
    rep(j, s + 1) cout << dp[i][j] << ' ';
    cout << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define rrep1(i, n) for (int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 998244353
#define INF 1000000000000000LL

using namespace std;

#define MAXNS 3001

ll facs[MAXNS];

vector<pll> dp[2];

// x^n in mod
ll modpow(ll x, ll n, ll mod) {
  if (n == 0)
    return 1;

  if (n % 2 == 0) {
    return modpow(x * x % mod, n / 2, mod) % mod;
  } else {
    return x * modpow(x, (n - 1), mod) % mod;
  }
}

// n! in mod
ll fac(ll n) { return facs[n]; }

// nCr in mod
ll comb(ll n, ll r) {
  if (n < 0 || n < r || r < 0)
    return 0;
  ll fn = fac(n);
  ll fr = fac(r);
  ll fn_r = fac(n - r);

  ll d = (modpow(fr, MOD - 2, MOD) * modpow(fn_r, MOD - 2, MOD)) % MOD;
  ll u = fn % MOD;

  ll result = u * d % MOD;

  return result;
}

// nPr in  mod
ll perm(ll n, ll r) {
  if (n < 0 || n < r || r < 0)
    return 0;
  ll fn = fac(n);
  ll fn_r = fac(n - r);

  ll d = modpow(fn_r, MOD - 2, MOD);
  ll u = fn % MOD;

  ll result = u * d % MOD;

  return result;
}

int main() {
  int n, s;
  cin >> n >> s;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  facs[0] = 1;
  rep(i, MAXNS) facs[i + 1] = (facs[i] * (i + 1)) % MOD;

  dp[0].push_back({0, 0});
  rep(i, n) {
    int cn = a[i];
    for (auto p : dp[0]) {
      if (p.second + cn <= s)
        dp[1].push_back({p.first + 1, p.second + cn});
      dp[1].push_back(p);
    }
    swap(dp[0], dp[1]);
    dp[1] = vector<pll>();
  }

  ll result = 0;
  for (auto p : dp[0]) {
    if (p.second != s)
      continue;

    result += modpow(2LL, n - p.first, MOD);
    result %= MOD;
  }

  cout << result << endl;

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

#include <bits/stdc++.h>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 998244353;

ll rep_square(ll a, ll b) {
  // return a^b
  ll ans = 1;
  ll base = a;
  while (b != 0) {
    if (b & 1) {
      ans *= base;
      ans %= mod;
    }
    base *= base;
    base %= mod;
    b >>= 1;
  }
  return ans;
}

int main() {
  ll n, s;
  cin >> n >> s;
  ll a[n];
  rep(i, n) { cin >> a[i]; }

  ll dp[n][s + 1] = {};
  dp[0][0] = 2;
  if (a[0] <= s)
    dp[0][a[0]] = 1;

  repd(i, 1, n) {
    rep(j, s + 1) {
      dp[i][j] = dp[i - 1][j] * 2;
      if (j - a[i] >= 0) {
        dp[i][j] += dp[i - 1][j - a[i]];
      }
      dp[i][j] %= mod;
    }
  }

  cout << dp[n - 1][s] << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 998244353;

ll rep_square(ll a, ll b) {
  // return a^b
  ll ans = 1;
  ll base = a;
  while (b != 0) {
    if (b & 1) {
      ans *= base;
      ans %= mod;
    }
    base *= base;
    base %= mod;
    b >>= 1;
  }
  return ans;
}

int main() {
  ll n, s;
  cin >> n >> s;
  ll a[n];
  rep(i, n) { cin >> a[i]; }

  map<ll, ll> dp[n][s + 1];

  dp[0][a[0]][1]++;

  repd(i, 1, n) {
    rep(j, s + 1) { dp[i][j] = dp[i - 1][j]; }
    if (a[i] <= s)
      dp[i][a[i]][1]++;
    repd(j, a[i] + 1, s + 1) {
      for (auto iter = dp[i - 1][j - a[i]].begin();
           iter != dp[i - 1][j - a[i]].end(); iter++) {
        dp[i][j][(iter->first) + 1] += iter->second;
      }
    }
  }

  ll ans = 0;

  for (auto iter = dp[n - 1][s].begin(); iter != dp[n - 1][s].end(); iter++) {
    // cout << iter->first << " " << iter->second << endl;
    ans += (iter->second * rep_square(2, n - iter->first)) % mod;
    ans %= 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 ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> pii;
#define rep(i, x, y) for (register int i = x; i < y; i++)
#define rept(i, x, y) for (register int i = x; i <= y; i++)
#define per(i, x, y) for (int i = x; i >= y; i--)
#define all(x) x.begin(), x.end()
#define pb push_back
#define fi first
#define se second
#define mes(a, b) memset(a, b, sizeof a)
#define mp make_pair
#define dd(x) cout << #x << "=" << x << " "
#define de(x) cout << #x << "=" << x << "\\n"
#define debug() cout << "I love Miyamizu Mitsuha forever.\\n"
const int inf = 0x3f3f3f3f;
const int maxn = 3005;
const int mod = 998244353;

ll dp[maxn][maxn];
ll a[maxn];
ll qpow(ll a, ll b) {
  ll ans = 1;
  for (; b; b >>= 1, a = a * a % mod)
    if (b & 1)
      ans = ans * a % mod;
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll ans = 0;
  int n, s;
  cin >> n >> s;
  rept(i, 1, n) cin >> a[i];
  //	for(int i=n;i>=1;i--) cin>>a[i];
  dp[0][0] = 1;
  rept(i, 1, n) {
    rept(j, 0, 3000) if (j >= a[i]) dp[i][j] =
        (dp[i - 1][j] * 2 + dp[i - 1][j - a[i]]) % mod;
    else dp[i][j] = dp[i - 1][j] * 2 % mod;
  }
  cout << dp[n][s] << "\\n";
  // cout<<ans<<"\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> pii;
#define rep(i, x, y) for (register int i = x; i < y; i++)
#define rept(i, x, y) for (register int i = x; i <= y; i++)
#define per(i, x, y) for (int i = x; i >= y; i--)
#define all(x) x.begin(), x.end()
#define pb push_back
#define fi first
#define se second
#define mes(a, b) memset(a, b, sizeof a)
#define mp make_pair
#define dd(x) cout << #x << "=" << x << " "
#define de(x) cout << #x << "=" << x << "\\n"
#define debug() cout << "I love Miyamizu Mitsuha forever.\\n"
const int inf = 0x3f3f3f3f;
const int maxn = 3005;
const int mod = 998244353;

ll dp[maxn][maxn];
ll a[maxn];

ll qpow(ll a, ll b) {
  ll ans = 1;
  for (; b; b >>= 1, a = a * a % mod)
    if (b & 1)
      ans = ans * a % mod;
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll ans = 0;
  int n, s;
  cin >> n >> s;
  rept(i, 1, n) cin >> a[i];
  //	for(int i=n;i>=1;i--) cin>>a[i];
  dp[0][0] = 1;
  rept(i, 1, n) {
    for (register int j = i; j >= 1; j--) {
      for (register int k = s; k >= a[i]; k--) {
        //			if(i==2&&j==2&&k==4)
        //dd(j-1),dd(k-a[i]),de(dp[j-1][k-a[i]]);
        dp[j][k] += dp[j - 1][k - a[i]];
        dp[j][k] %= mod;
      }
    }
    //	dd(i);dd(dp[2][4]);de(dp[1][2]);
  }
  rept(i, 1, n) { ans = (ans + qpow(2, n - i) * dp[i][s]) % mod; }
  cout << ans << "\\n";
  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cout << name << " : " << arg1 << std::endl;
  // use cerr if u want to display at the bottom
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
#define mod 998244353
int main() {
  ll n, s;
  cin >> n >> s;
  ll a[n];
  REP(i, n) cin >> a[i];
  ll dp[n + 1][s + 1];
  memset(dp, 0, sizeof dp);
  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= s; j++) {
      dp[i + 1][j] = (dp[i + 1][j] + 2 * dp[i][j]) % mod;
      if (j + a[i] <= s) {
        dp[i + 1][j + a[i]] = (dp[i + 1][j + a[i]] + dp[i][j]) % mod;
      }
    }
  }
  cout << dp[n][s] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (ll i = 0; i < n; i++)
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cout << name << " : " << arg1 << std::endl;
  // use cerr if u want to display at the bottom
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
ll n, s, *a;
map<string, ll> dp;
ll f(ll i, ll t, ll u) {
  string x = to_string(i) + " " + to_string(t) + " " + to_string(u);
  if (dp.find(x) != dp.end())
    return dp[x];
  if (i == n) {
    return dp[x] = (u == s);
  }
  return dp[x] = f(i + 1, t, u) + f(i + 1, t + a[i], u) +
                 f(i + 1, t + a[i], u + a[i]);
}
int main() {
  cin >> n >> s;
  a = new ll[n];
  REP(i, n) cin >> a[i];
  cout << f(0, 0, 0);
  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int A[3005];

long long memo[3005][3005];
const long long modConst = 998244353;

long long DP(int N, int S) {
  if (S < 0)
    return 0;

  if (N == 0 && S == 0)
    return 1;

  if (N == 0)
    return 0;

  if (memo[N][S] != -1)
    return memo[N][S];

  long long putToBoth = DP(N - 1, S - A[N]);
  long long putToTOnly = DP(N - 1, S);
  long long putToNone = DP(N - 1, S);

  memo[N][S] = (putToBoth + putToTOnly + putToNone) % modConst;
  return memo[N][S];
}

int main() {
  int N, S;
  scanf("%d%d", &N, &S);

  for (int i = 1; i <= N; i++)
    scanf("%d", &A[i]);

  for (int i = 0; i < 3005; i++) {
    for (int j = 0; j < 3005; j++)
      memo[i][j] = -1;
  }

  long long ans = DP(N, S);
  printf("%lld", ans);
}


Error: TLE

Fixed submission:

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

int A[3005];

long long memo[3005][3005];
const long long modConst = 998244353;

long long DP(int N, int S) {
  if (S < 0)
    return 0;

  if (N == 0 && S == 0)
    return 1;

  if (N == 0)
    return 0;

  if (memo[N][S] != -1)
    return memo[N][S];

  long long putToBoth = DP(N - 1, S - A[N]);
  long long putToTOnly = DP(N - 1, S);
  long long putToNone = DP(N - 1, S);

  return (putToBoth + putToTOnly + putToNone) % modConst;
}

int main() {
  int N, S;
  scanf("%d%d", &N, &S);

  for (int i = 1; i <= N; i++)
    scanf("%d", &A[i]);

  for (int i = 0; i < 3005; i++) {
    for (int j = 0; j < 3005; j++)
      memo[i][j] = -1;
  }

  long long ans = DP(N, S);
  printf("%lld", ans);
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
ll n, s;
ll a[3010];
ll f[3010];
ll inv2;
ll ksm(ll aa, ll b) {
  ll ret = 1;
  while (b) {
    if (b & 1)
      ret = (ret * aa) % MOD;
    aa = (aa * aa) % MOD;
    b >>= 1;
  }
  return ret;
}
int main() {
  cin >> n >> s;
  for (ll i = 1; i <= n; i++)
    cin >> a[i];
  inv2 = ksm(2, MOD - 2);
  f[0] = ksm(2, n);
  for (ll i = 1; i <= n; i++) {
    for (ll k = s; k >= a[i]; k--) {
      f[k] = (f[k] + f[k - a[i]] * inv2) % MOD;
    }
  }
  cout << f[s];
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
ll n, s;
ll a[3010];
ll f[3010][3010]; // f[i][j]: 选i个，和为j的方案数
ll ksm(ll aa, ll b) {
  ll ret = 1;
  while (b) {
    if (b & 1)
      ret = (ret * aa) % MOD;
    aa = (aa * aa) % MOD;
    b >>= 1;
  }
  return ret;
}
ll ans;
int main() {
  cin >> n >> s;
  for (ll i = 1; i <= n; i++)
    cin >> a[i];
  f[0][0] = 1;
  for (ll i = 1; i <= n; i++) {
    for (ll j = i; j >= 1; j--) {
      for (ll k = s; k >= a[i]; k--) {
        f[j][k] = (f[j][k] + f[j - 1][k - a[i]]) % MOD;
      }
    }
  }
  for (ll i = 0; i <= n; i++) {
    ans += f[i][s] * ksm(2, n - i);
    ans %= MOD;
  }
  cout << ans;
  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

const int M = 3e3 + 1;
int n, arr[M], memo[M][M], mod = 998244353, halph;

int add(int a, int b) { return a + b - (a + b >= mod) * mod; }
int sub(int a, int b) { return a - b + (a - b < 0) * mod; }
int mul(int a, int b) { return (1ll * a * b) % mod; }
int powM(int n, int p) {
  return (!p ? 1 : (p & 1) ? mul(n, powM(n, p - 1)) : powM(mul(n, n), p / 2));
}
int divM(int a, int b) { return mul(a, powM(b, mod - 2)); }

int solve(int i, int cur) {
  if (cur < 0)
    return 0;
  if (i == n)
    return !cur;

  int &res = memo[i][cur];
  if (res == -1)
    res = add(mul(halph, solve(i + 1, cur - arr[i])), solve(i + 1, cur));
  return res;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  memset(memo, -1, sizeof memo);
  int s;
  cin >> n >> s;
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  halph = divM(1, 2);
  cout << mul(powM(2, n), solve(0, s)) << "\\n";

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const int M = 3e3;
int n, arr[M], memo[M][M + 1], mod = 998244353;

int add(int a, int b) { return a + b - (a + b >= mod) * mod; }
int sub(int a, int b) { return a - b + (a - b < 0) * mod; }
int mul(int a, int b) { return (1ll * a * b) % mod; }
int powM(int n, int p) {
  return (!p ? 1 : (p & 1) ? mul(n, powM(n, p - 1)) : powM(mul(n, n), p / 2));
}
int divM(int a, int b) { return mul(a, powM(b, mod - 2)); }

int solve(int i, int cur) {
  if (cur < 0)
    return 0;
  if (i == n)
    return !cur;

  int &res = memo[i][cur];
  if (res == -1)
    res = add(mul(divM(1, 2), solve(i + 1, cur - arr[i])), solve(i + 1, cur));
  return res;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  memset(memo, -1, sizeof memo);
  int s;
  cin >> n >> s;
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  cout << mul(powM(2, n), solve(0, 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 = 1000000007;
const ll MOD2 = 998244353;
const double PI = acos(-1);
const ll INF = 1e18;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge {
  ll to, cost;
};

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const double PI = acos(-1);
const ll INF = 1e18;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge {
  ll to, cost;
};

ll pow_mod(ll x, ll y) {
  if (y == 0) {
    return 1;
  } else if (y % 2 == 1) {
    return pow_mod(x, y - 1) * x % MOD2;
  } else {
    ll t = pow_mod(x, y / 2);
    return t * t % MOD2;
  }
}

int main() {
  ll n, s;
  cin >> n >> s;
  vl a(n);
  rep(i, n) { cin >> a[i]; }
  vvl dp(s + 1);
  dp[0].push_back(0);
  rep(i, n) {
    for (ll j = s - a[i]; j >= 0; j--) {
      rep(k, dp[j].size()) { dp[a[i] + j].push_back(dp[j][k] + 1); }
    }
  }
  ll z = dp[s].size();
  /*rep(i,z){
    cout << dp[s][i] << endl;
  }*/
  ll ans = 0;
  rep(i, z) {
    ans += pow_mod(2, n - dp[s][i]);
    ans %= MOD2;
  }
  cout << ans << endl;
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

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

template <typename T>
constexpr T inf =
    static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) +
    7;
constexpr llong mod = 998244353;

llong pow_mod(llong n, llong m) {
  if (m == 0)
    return 1;
  if (m == 1)
    return n;

  llong ret = pow_mod(n, m / 2);
  ret = ret * ret % mod;
  if (m & 1) {
    ret = ret * n % mod;
  }
  return ret;
}

int main() {
  llong N, S;
  vector<llong> A;

  cin >> N >> S;
  A.resize(N);
  for (auto &in : A) {
    cin >> in;
  }

  vector<llong> dp(S + 1);
  for (int i = 0; i < N; ++i) {
    vector<llong> now(S + 1);
    for (int j = S; j >= 0; --j) {
      now[j] = dp[j] * 2;
      if (j >= A[i]) {
        now[j] += dp[j - A[i]];
      }
      now[j] %= mod;
    }
    if (A[i] <= S) {
      now[A[i]] += pow_mod(2, i);
    }
    swap(dp, now);
  }

  cout << dp[S] << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

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

template <typename T>
constexpr T inf =
    static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) +
    7;
constexpr llong mod = 998244353;

llong pow_mod(llong n, llong m) {
  if (m == 0)
    return 1;
  if (m == 1)
    return n;

  llong ret = pow_mod(n, m / 2);
  ret = ret * ret % mod;
  if (m & 1) {
    ret = ret * n % mod;
  }
  return ret;
}

int main() {
  llong N, S;
  vector<llong> A;

  cin >> N >> S;
  A.resize(N);
  for (auto &in : A) {
    cin >> in;
  }

  vector<llong> dp(S + 1);
  for (int i = 0; i < N; ++i) {
    vector<llong> now(S + 1);
    for (int j = S; j >= 0; --j) {
      now[j] = dp[j] * 2;
      if (j >= A[i]) {
        now[j] += dp[j - A[i]];
      }
      now[j] %= mod;
    }
    now[A[i]] += pow_mod(2, i);
    swap(dp, now);
  }

  cout << dp[S] << endl;

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define ve vector
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
const int mod = 998244353;
int main() {
  int n, s;
  cin >> n >> s;
  ve<int> a(n);
  rep(i, n) cin >> a[i];
  ve<ve<ll>> dp(n + 1, ve<ll>(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] <= s) {
        (dp[i + 1][j + a[i]] = dp[i][j]) %= mod;
      }
    }
  }
  cout << dp[n][s] << endl;
  return 0;
}

Error: 0

Fixed submission:

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

const int mod = 998244353;

int main() {
  int n, s;
  cin >> n >> s;
  ve<ll> a(n);
  rep(i, n) cin >> a[i];

  ve<ve<ve<ll>>> dp(n + 2, ve<ve<ll>>(10 * s, ve<ll>(n + 2)));

  dp[0][0][0] = 1;
  int sum = 0;
  rep(i, n) {
    rep(j, min(s, sum) + 1) {
      rep(k, i + 1) {
        (dp[i + 1][j + a[i]][k + 1] += dp[i][j][k]) %= mod;
        (dp[i + 1][j][k] += dp[i][j][k]) %= mod;
      }
    }
    sum += a[i];
  }
  ll ans = 0;
  ll c = 1;
  for (int i = n; i > 0; i--) {
    (ans += c * dp[n][s][i]) %= mod;
    (c *= 2) %= mod;
  }
  cout << ans << endl;
  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int MOD = 998244353;

int A[3003];
int dp[3003][3003];

int solve(int n, int s) {
  if (n == 0)
    return (s == 0);

  if (dp[n][s] != -1)
    return dp[n][s];

  long long ans = solve(n - 1, s) * 2LL;

  if (s >= A[n])
    ans += solve(n - 1, s - A[n]);

  return dp[n][s] = ans % MOD;
}

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

  int n, s;
  cin >> n >> s;

  for (int i = 1; i <= n; i++)
    cin >> A[i];

  memset(dp, -1, sizeof(dp));
  cout << solve(n, s) << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

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

const int MOD = 998244353;

int A[3003], C[3003][3003], two[3003];
map<vector<int>, int> dp;

int solve(int pos, int n, int s) {
  if (s == 0)
    return (n == 0);

  if (pos == 0)
    return 0;

  if (dp.count({pos, n, s}))
    return dp[{pos, n, s}];

  long long ans = 0;

  for (int i = 0; i <= n && i * pos <= s && i <= A[pos]; i++)
    ans += 1LL * solve(pos - 1, n - i, s - i * pos) * C[A[pos]][i];

  return dp[{pos, n, s}] = ans % MOD;
}

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

  int n, s;
  cin >> n >> s;

  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;

    A[x]++;
  }

  two[0] = 1;

  for (int i = 1; i <= n; i++)
    two[i] = two[i - 1] * 2LL % MOD;

  for (int i = 0; i <= n; i++)
    C[i][0] = 1;

  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]);

      if (C[i][j] >= MOD)
        C[i][j] -= MOD;
    }

  long long ans = 0;

  for (int i = 1; i <= n; i++)
    ans += 1LL * solve(s, i, s) * two[n - i];

  cout << ans % MOD << "\\n";
  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
const int N = 3e3 + 3, MOD = 998244353;
int a[N], dp[N];

void mod(int &a) {
  if (a >= MOD)
    a -= MOD;
}
int mul(int a, int b) { return 1ll * a * b % MOD; }
int Pow(int a, int b) {
  int res = 1;
  for (; b; b >>= 1, a = mul(a, a))
    if (b & 1)
      res = mul(res, a);
  return res;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, S;
  scanf("%d%d", &n, &S);
  for (int i = 0; i < n; i++)
    scanf("%d", a + i);
  dp[0] = Pow(2, n);
  int inv = Pow(2, MOD - 2);
  for (int i = 0; i < n; i++)
    for (int j = S; j >= a[i]; j--)
      dp[j] += mul(dp[j - a[i]], inv), mod(dp[j]);
  printf("%d\\n", dp[S]);

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
const int N = 3e3 + 3, MOD = 1e9 + 7;
int a[N], dp[N];

int mod(int &a) {
  if (a >= MOD)
    a -= MOD;
}
int mul(int a, int b) { return 1ll * a * b % MOD; }
int Pow(int a, int b) {
  int res = 1;
  for (; b; b >>= 1, a = mul(a, a))
    if (b & 1)
      res = mul(res, a);
  return res;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, S;
  scanf("%d%d", &n, &S);
  for (int i = 0; i < n; i++)
    scanf("%d", a + i);
  dp[0] = Pow(2, n);
  int inv = Pow(2, MOD - 2);
  for (int i = 0; i < n; i++)
    for (int j = S; j >= a[i]; j--)
      dp[j] += mul(dp[j - a[i]], inv), mod(dp[j]);
  printf("%d\\n", dp[S]);

  return 0;
}