Problem:


Score : 600 points

Problem Statement

Given are a sequence of N positive integers A_1, A_2, \ldots, A_N and another positive integer S.

For a non-empty subset T of the set \{1, 2, \ldots , N \}, let us define f(T) as follows:

f(T) is the number of different non-empty subsets \{x_1, x_2, \ldots , x_k \} of T such that A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S.

Find the sum of f(T) over all 2^N-1 subsets T of \{1, 2, \ldots , N \}. Since the sum can be enormous, print it modulo 998244353.

Constraints

All values in input are integers.

1 \leq N \leq 3000

1 \leq S \leq 3000

1 \leq A_i \leq 3000

Input

Input is given from Standard Input in the following format:

N S
A_1 A_2 ... A_N

Output

Print the sum of f(T) modulo 998244353.

Sample Input 1

3 4
2 2 4

Sample Output 1

6

For each T, the value of f(T) is shown below. The sum of these values is 6.

f(\{1\}) = 0

f(\{2\}) = 0

f(\{3\}) = 1 (One subset \{3\} satisfies the condition.)

f(\{1, 2\}) = 1 (\{1, 2\})

f(\{2, 3\}) = 1 (\{3\})

f(\{1, 3\}) = 1 (\{3\})

f(\{1, 2, 3\}) = 2 (\{1, 2\}, \{3\})

Sample Input 2

5 8
9 9 9 9 9

Sample Output 2

0

Sample Input 3

10 10
3 1 4 1 5 9 2 6 5 3

Sample Output 3

3296



Sample input:
3 4
2 2 4


Sample output:
6

Submission status: Time Limit Exceeded

Solution code:
MOD = 998244353


def encode(num, total, S):
    return num * (S+1) + total


def decode(val, S):
    return val // (S+1), val % (S+1)


def main():
    N, S = map(int, input().split())
    A = list(sorted(map(int, input().split()), reverse=True))
    prev = {encode(0, 0, S): 1}
    for i in range(N):
        cur = {k: prev[k] for k in prev}
        for prevkey in prev:
            num, total = decode(prevkey, S)
            if total + A[i] > S:
                continue
            key = encode(num+1, total + A[i], S)
            if key in cur:
                cur[key] = cur[key] + prev[prevkey]
            else:
                cur[key] = prev[prevkey]
        prev = cur
    ans = 0
    for num in range(1, N+1):
        key = encode(num, S, S)
        if key in cur:
            ans = (ans + cur[key] * pow(2, N-num, MOD)) % MOD
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 998244353
 
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, S = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    dp=[dict() for _ in range(S+1)]
    dp[0][0]=1
    for i,a in enumerate(A):
        for s in range(S,0,-1):
            if s-a>=0:
                for ls,val in dp[s-a].items():
                    dp[s][ls+1]=dp[s].get(ls+1,0)+dp[s-a][ls]
    ans=0
    t2=[1]
    for i in range(1,N+1):
        t2.append(2*t2[-1]%mod)
    for l,val in dp[S].items():
        ans+=(val*t2[N-l])%mod
        ans%=mod
    #print(dp[S])
    print(ans)






if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
import sys
sys.setrecursionlimit(10**9)
input=sys.stdin.readline
from collections import deque,defaultdict
import heapq
from itertools import combinations
import bisect

def main():
  mod=998244353
  pp=pow(2,mod-2,mod)

  n,s=map(int,input().split())
  l=list(map(int,input().split()))
#l.sort()
  dp=[[0 for j in range(s+1)] for i in range(n+1)]
  dp[0][0]=pow(2,n,mod)

  for i in range(n):
      for j in range(s+1):
          if dp[i][j]>=1:
              if j+l[i]<=s:
                  dp[i+1][j+l[i]]+=dp[i][j]*pp# +pow(2,n-1,mod)
                  dp[i+1][j+l[i]]%=mod
              dp[i+1][j]+=dp[i][j]
  print(dp[-1][-1]%mod)
if __name__=='__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
n,s=map(int,input().split())
a=list(map(int,input().split()))
mod=998244353
dp=[[0 for i in range(s+1)] for j in range(n+1)]
dp[0][0]=1
for i in range(1,n+1):
    see=a[i-1]
    for j in range(s+1):
        dp[i][j]=dp[i-1][j]*2
        dp[i][j]%=mod
        if see>j:
            continue
        dp[i][j]+=dp[i-1][j-see]
        dp[i][j]%=mod

print(dp[-1][-1])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys

N,S, *A = map(int, sys.stdin.buffer.read().split())
mod = 998244353
A = sorted(A)

answer = [0 for _ in range(S+1)]
power2 = 1
total = 0

for a in A:
  if total<S:
    total = min(S,a+total)
  for i in range(total,0,-1):
    if i>a:
      answer[i] = (2*answer[i]+answer[i-a])%mod
    elif i==a:
      answer[i] = (2*answer[i]+power2)%mod
    else:
      answer[i] = (2*answer[i])%mod
  power2 = (2*power2)%mod

print(answer[S])

Submission status: Time Limit Exceeded

Solution code:
N, S = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353

DP = [[0] * (S+1) for _ in range(N+1)]
Pre = [[[] for _ in range(S+1)] for _ in range(N+1)]

DP[0][0] = 1
Pre[0][0].append([-1])

for i, a in enumerate(A):
    for j in range(S+1):
        b = DP[i][j]
        if b > 0:
            DP[i + 1][j] += DP[i][j]
            for P in Pre[i][j]:
                Pre[i+1][j].append(P)
        if a + j <= S:
            DP[i + 1][j + a] += DP[i][j]
            for P in Pre[i][j]:
                Pre[i + 1][j+a].append(P + [i])
ans = 0
for L in Pre[N][S]:
    ans += pow(2, N - len(L) + 1, mod)
    ans %= mod

print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
n, s = map(int, input().split())
a = list(map(int, input().split()))
mod = 998244353

dp = [[[0 for i in range(s + 1)] for i in range(n + 1)] for i in range(n + 1)]
dp[0][0][0] = 1
max_sum = 0
for i in range(1, n + 1):
    max_sum += a[i-1]
    for j in range(i + 1):
        for k in range(min(max_sum + 1, s + 1)):
            if j != 0:
                if k >= a[i-1]:
                    dp[i][j][k] = (dp[i-1][j-1][k-a[i-1]] + dp[i-1][j][k]) % mod
                else:
                    dp[i][j][k] = dp[i-1][j][k]
            else:
                dp[i][j][k] = dp[i-1][j][k]
dp2 = [dp[n][i][s] for i in range(n + 1)]
ans = 0
for i in range(n + 1):
    temp = dp2[i] * pow(2, n - i, mod)
    ans += temp
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, S = map(int, input().split())
A = list(map(int, input().split()))
 
B = []
for a in A:
    if a <= S:
        B.append(a)
 
def get_integral_value_combination(list, target):
    def a(idx, l, r, t):
        if t == sum(l): r.append(l)
        elif t < sum(l): return
        for u in range(idx, len(list)):
            a((u + 1), l + [list[u]], r, t)
        return r
    return a(0, [], [], target)
 
vc = get_integral_value_combination(B, S)
ans = 0
 
for comb in vc:
    tmp = N - len(comb)
    ans += 2**tmp
 
ans %= 998244353
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, S = map(int, input().split())
A = list(map(int, input().split()))

MOD = 998244353

A.sort()
s = 0
for idx, a in enumerate(A):
    s += a
    if s > S:
        break
idx += 1

dp = [[[0] * (idx + 1) for _ in range(S + 1)] for _ in range(N + 1)]
dp[0][0][0] = 1

for i in range(N):
    a = A[i]
    for j in range(S + 1):
        for k in range(idx + 1):
            a = A[i]
            here = dp[i][j][k]
            if j + a <= S and k + 1 <= idx:
                dp[i + 1][j + a][k + 1] += here
            dp[i + 1][j][k] += here

cnt = 0
K = dp[-1][-1]
for i, c in enumerate(K):
    cnt += c * (pow(2, N - i, MOD))
    cnt %= MOD

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def main():
    MOD = 998244353

    N, S = map(int, input().split())
    *A, = map(int, input().split())

    dp = [[] for _ in range(S + 1)]
    dp[0] += [0]
    # dp[和]:=パターン数

    for i, x in enumerate(A):
        for s in range(S, x - 1, -1):
            dp[s] += (b | (1 << i) for b in dp[s - x])

    pow2 = []
    t = 1
    for _ in range(N + 1):
        pow2.append(t)
        t = t * 2 % MOD

    ans = 0
    for b in dp[S]:
        j = bin(b).count('1')
        ans = (ans + pow2[N - j]) % MOD
    print(ans)

    # print(*(bin(b) for b in dp[S]))


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok

Submission status: Time Limit Exceeded

Solution code:
N, S = map(int, input().split())
A = list(map(int, input().split()))

def get_integral_value_combination(list, target):
    def a(idx, l, r, t):
        if t == sum(l): r.append(l)
        elif t < sum(l): return
        for u in range(idx, len(list)):
            a((u + 1), l + [list[u]], r, t)
        return r
    return a(0, [], [], target)

vc = get_integral_value_combination(A, S)
ans = 0

for comb in vc:
    tmp = N - len(comb)
    ans += 2**tmp

ans %= 998244353
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,s=map(int,input().split())
a=list(map(int,input().split()))
b=list()
for i in range(n):
    b.append(0)
res=list()
now=0
weight=0
ans=0
while True:
    if now>=n:
        if not 1 in b:
            break
        else:
            idx="".join(map(str,b)).rfind("1")
            b[idx]=0
            now=idx+1
            weight-=a[idx]
            continue
    if weight+a[now]<s:
        b[now]=1
        weight+=a[now]
        now+=1
        continue
    elif weight+a[now]==s:
        res.append(n-sum(b)-1)
        now+=1
    else:
        now+=1
        
for x in res:
    y=1
    for i in range(x):
        y*=2
        y=y%998244353
    ans+=y
    ans=ans%998244353
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy

mod = 998244353

n, s = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

dp = [{} for i in range(s+1)]
dp[0][0] = 1

for ai in a:
    nex = []
    for i in range(s+1):
        nex.append(copy.copy(dp[i]))
    for i in range(s-ai+1):
        for k in dp[i]:
            cnt = dp[i][k]
            if k+1 in nex[i+ai]:
                nex[i+ai][k+1] += cnt
            else:
                nex[i+ai][k+1] = cnt
    dp = nex

rui = [1]

for i in range(n):
    tmp = rui[-1]
    tmp *= 2
    tmp %= mod
    rui.append(tmp)

ans = 0

for k in dp[s]:
    cnt = dp[s][k]
    ans += cnt * rui[n-k]
    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,s=map(int,input().split())
A=list(map(int,input().split()))

from itertools import combinations
sub=[]
for i in range(len(A) + 1):
    for c in combinations(A, i):
        sub.append(c)

ans=0
for i in sub:
    if sum(i)==s:
        ans+=(2**(n-len(i)))

print(ans%998244353)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 998244353
 
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, S = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    dp=[dict() for _ in range(S+1)]
    dp[0][0]=1
    for i,a in enumerate(A):
        
        for s in range(S,0,-1):
            if s-a>=0:
                for ls,val in dp[s-a].items():
                    dp[s][ls+1]=dp[s].get(ls+1,0)+dp[s-a][ls]
    ans=0
    for l,val in dp[S].items():
        
        ans+=val*pow(2,N-l,mod)
        ans%=mod
    #print(dp[S])
    print(ans)






if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353

dp = [0] * (S + 1)
dp[0] = 1

for a in A:
    newDp = [d * 2 % MOD for d in dp]

    for s in range(S + 1):
        if s + a <= S:
            newDp[s + a] += dp[s]

    dp = newDp

print(dp[S] % MOD)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
import sys
sys.setrecursionlimit(10**9)
from collections import deque,defaultdict
import heapq
from itertools import combinations
import bisect


mod=998244353
pp=pow(2,mod-2,mod)

n,s=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
dp=[[0 for j in range(s+1)] for i in range(n+1)]
dp[0][0]=pow(2,n,mod)
d=defaultdict(int)

for i in range(n):
    for j in range(s+1):
        if dp[i][j]>=1:
            if j+l[i]<=s:
                dp[i+1][j+l[i]]+=dp[i][j]*pp# +pow(2,n-1,mod)
                dp[i+1][j+l[i]]%=mod
            dp[i+1][j]+=dp[i][j]
print(dp[-1][-1]%mod)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import bisect
import collections
import sys

sys.setrecursionlimit(1000000)
ACMOD = 1000000007
INF = 1 << 62

MOD = 998244353  # type: int

def s(A, S, N):
    d = dict()
    d[0, 0] = 1  # left:vale right:count
    for i, a in enumerate(A):
        for (left, right) in sorted(d.keys(), reverse=True):
            if left + a > S:
                continue
            if (left + a, right + 1) in d:
                d[left + a, right + 1] += d[left, right]
            else:
                d[left + a, right + 1] = d[left, right]
    return d


def solve(N: int, S: int, A: "List[int]"):
    A.sort()
    d = s((A), S, N)
    ans = 0
    for val, count in d.keys():
        if val != S:
            continue
        ans += d[val, count] * 2 ** (N - count)
        ans %= 998244353
    print(ans)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, S, (A))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap



from copy import deepcopy
@mt
def slv(N, S, A):

    memo = [Counter() for _ in range(S+1)]
    memo[0] = {0:1}
    for a in A:
        nm = []
        for s in range(S+1):
            nm.append(deepcopy(memo[s]))
        for s in range(S+1):
            if s + a <= S and len(memo[s]) > 0:
                for k, v in memo[s].items():
                    nm[s+a][k+1] += v
        memo = nm

    mod = 998244353
    ans = 0
    for k, m in memo[S].items():
        l = m * 2**(N-k)
        ans += l
        ans %= mod




    return ans


def main():
    N, S = read_int_n()
    A = read_int_n()
    print(slv(N, S, A))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
MOD = 998244353

n, s = map(int, input().split())
a = [int(item) for item in input().split()]
# dp[i-th item][j val] : tuple(cnt, used cnt)
dp = [[dict() for _ in range(s+1)] for _ in range(n + 1)]
dp[0][0][0] = 1

for i, item in enumerate(a):
    for j in range(s):
        for uc, c in dp[i][j].items():
            if uc not in dp[i+1][j]:
                dp[i+1][j][uc] = c
            else:
                dp[i+1][j][uc] += c
            if j + item > s:
                continue
            if uc + 1 not in dp[i+1][j + item]:
                dp[i+1][j + item][uc + 1] = c
            else:
                dp[i+1][j + item][uc + 1] += c

ans = 0
for dics in dp:
    for key, val in dics[-1].items():
        ans += pow(2, n - key, MOD) * val
        ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,s=map(int,input().split())
a=list(map(int,input().split()))
p=998244353

data=[[0]*(s+1) for i in range(n)]

gen=data[0]
gen[0]=2
if(a[0]<=s):
    gen[a[0]]+=1

for i in range(1,n):
    gen=data[i]
    mae=data[i-1]
    for j in range(s+1):
        gen[j]=mae[j]*2
        if(j-a[i]>=0 and j-a[i]<=s):
            gen[j]+=mae[j-a[i]]
        gen[j]%=p

print(data[-1][-1])

Submission status: Time Limit Exceeded

Solution code:

MOD = 998244353

def main():
    N, S = map(int, input().split())
    A = list(map(int, input().split()))
    print(solve(N, S, A))

def solve(N, S, A):
    dp = [[0]*(S+1) for _ in range(N+1)]
    dp[0][0] = 1
    # for line in dp:
    #     print(line)
    for n in range(1, N+1):
        an = A[n-1]
        # print(an)
        for s in range(S+1):
            part1 = dp[n-1][s]
            part2 = 0
            if s-an >= 0:
                part2 = dp[n-1][s-an]
            dp[n][s] = (2*part1 + part2) % MOD
        # for line in dp:
        #     print(line)
    return dp[N][S]

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N,S = map(int,input().split())
A = list(map(int,input().split()))
dp = [[] for i in range(S+1)]
dp[0].append(0)
for i in range(1,N+1):
    a = A[i-1]
    dp_1 = [[] for i in range(S+1)]
    for j in range(S-a+1):
        if len(dp[j]) != 0:
            for k in dp[j]:
                dp_1[j+a].append(k+1)
    for j in range(S+1):
        if len(dp[j]) != 0:
            for k in dp[j]:
                dp_1[j].append(k)
    dp = dp_1
A = dp[S]
A.sort()
ans = 0
mod = 998244353
for a in A:
    x = N - a
    ans += 2**x % mod
    ans = ans % mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, S = map(int, input().split())

*A, = map(int, input().split())

mod = 998244353

sumT = [0]*6005
sumT[0] = 1
sumT[A[0]] = 1

for a in A[1:]:
    for j in range(3001):
        sumT[j] *= 2

    for j in range(3000, -1, -1):
        sumT[j+a] += sumT[j] // 2
        sumT[j+a] %= mod
        sumT[j] %= mod

    sumT[0] += 1
    sumT[0] %= mod

    sumT[a] += 1
    sumT[a] %= mod


print(sumT[S] % mod)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from itertools import combinations_with_replacement
import sys
sys.setrecursionlimit(10 ** 9)

mod = 998244353

n, s = map(int, input().split())
a = list(map(int, input().split()))

bin = [1]
for _ in range(n - 1):
    bin.append((bin[-1] * 2) % mod)
    
lst = []

zero = 0
for num in a:
    if num > s:
        continue
    if num == s:
        zero += 1
        continue
    lst.append(num % s)
lst.sort()
ans = (zero * bin[-1]) % mod
length = len(lst)

def knapsack(pos, total, num):
    global ans
    if total == s:
        ans = (ans + bin[-num]) % mod
        return
    if pos == length:
        return
    if total + lst[pos] <= s:
        knapsack(pos + 1, total + lst[pos], num + 1)
        knapsack(pos + 1, total, num)

knapsack(0, 0, 0)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import bisect
import collections
import sys

sys.setrecursionlimit(1000000)
ACMOD = 1000000007
INF = 1 << 62

MOD = 998244353  # type: int
import numpy as np
from numba import njit

@njit(cache=True)
def s(A, S, ruiseki, N):
    d = dict()
    d[0, 0] = 1  # left:vale right:count
    for i, a in enumerate(A):
        for (left, right) in sorted(d.keys(), reverse=True):
            if left + a > S:
                continue
            if left + ruiseki[N - i] < S:
                break
            if (left + a, right + 1) in d:
                d[left + a, right + 1] += d[left, right]
            else:
                d[left + a, right + 1] = d[left, right]
    return d


def solve(N: int, S: int, A: "List[int]"):
    A.sort(reverse=True)
    ruiseki = [0]
    for a in A[::-1]:
        ruiseki.append(ruiseki[-1] + a)
    d = s(np.array(A), S, np.array(ruiseki), N)
    ans = 0
    for val, count in d.keys():
        if val != S:
            continue
        ans += d[val, count] * 2 ** (N - count)
        ans %= 998244353
    print(ans)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, S, (A))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
    input = sys.stdin.readline
    n, s = map(int, input().split())
    a = [int(x) for x in input().split()]
    mod = 998244353
    
    dp = [dict() for _ in range(s+1)]
    
    judge = dict()
    for i in range(n):
        for j in range(s-1, -1, -1):
            if dp[j] != judge:
                if a[i]+j <= s:
                    for k, v in dp[j].items():
                        if k+1 in dp[a[i]+j]:
                            key = (v+dp[a[i]+j][k+1])%mod
                            dp[a[i]+j][k+1] = key
                        else:
                            dp[a[i]+j][k+1] = v
            if j == 0:
                if a[i] <= s:
                    if 1 in dp[a[i]]:
                        key = (dp[a[i]][1]+1)%mod
                        dp[a[i]][1] = key 
                    else:
                        dp[a[i]][1] = 1
    
    ans = 0
    count = 1
    for k in range(n, 0, -1):
        if k in dp[s]:
            ans += (count*dp[s][k])%mod
            ans %= mod
        count *= 2
        count %= mod
    
    print(ans)
    

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from math import factorial as fac
from functools import lru_cache
import sys
from operator import *
from functools import *
from itertools import *

sys.setrecursionlimit(100000)

n, s = map(int, input().split())
l = [int(i)for i in input().split()]
l.sort()
cum = ([0] + list(accumulate(l, add)))[::-1]
# print(cum)
mod = 998244353


@lru_cache(None)
def f(i, tot, nn):
    if cum[i] + tot + 1 < s:
        return 0
    elif tot == s:
        return (1 << n - nn) % mod
    else:
        z = 0
        for j in range(n - 1, i - 1, -1):
            newt = tot + l[j]
            if newt <= s:
                z = (z + f(j + 1, newt, nn + 1)) % mod
        return z


print(f(0, 0, 0) % mod)

Submission status: Time Limit Exceeded

Solution code:
MOD = 998244353


def main():
    N, S = map(int, input().split())
    A = list(sorted(map(int, input().split())))
    prev = {(0, 0): 1}
    for i in range(N):
        cur = {k: prev[k] for k in prev}
        for num, total in prev:
            if total + A[i] > S:
                continue
            key = (num+1, total + A[i])
            if key in cur:
                cur[key] = cur[key] + prev[(num, total)]
            else:
                cur[key] = prev[(num, total)]
        prev = cur
    ans = 0
    for num in range(1, N+1):
        if (num, S) in cur:
            ans = (ans + cur[(num, S)] * pow(2, N-num, MOD)) % MOD
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N, S = map(int, input().split())
A = list(map(int, input().split()))

B = []
for a in A:
    if a <= S:
        B.append(a)

def get_integral_value_combination(list, target):
    def a(idx, l, r, t):
        if t == sum(l): r.append(l)
        elif t < sum(l): return
        for u in range(idx, len(list)):
            a((u + 1), l + [list[u]], r, t)
        return r
    return a(0, [], [], target)

vc = get_integral_value_combination(B, S)
ans = 0

for comb in vc:
    tmp = N - len(comb)
    ans += 2**tmp

ans %= 998244353
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,s=map(int,input().split())
a=[int(j)for j in input().split()]
from collections import defaultdict
dp=[defaultdict(int)for i in range(s+1)]
dp[0][0]=1
for i in a:
    for j in range(s+1-i)[::-1]:
        for k in dp[j]:
            dp[i+j][k+1]+=dp[j][k]
mod=998244353
ans=0
for i in dp[s]:
    ans=(ans+(dp[s][i]*pow(2,n-i,mod))%mod)%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 998244353
 
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, S = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    dp=[[] for _ in range(S+1)]
    dp[0]=[0]
    for i,a in enumerate(A):
        
        for s in range(S,0,-1):
            if s-a>=0:
                for ls in dp[s-a]:
                    dp[s].append(ls+1)
    ans=0
    for p in dp[S]:
        
        ans+=pow(2,N-p,mod)
        ans%=mod
    #print(dp[S])
    print(ans)






if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import bisect
import collections
import sys

sys.setrecursionlimit(1000000)
ACMOD = 1000000007
INF = 1 << 62

MOD = 998244353  # type: int
import numpy as np
from numba import jit
@jit(nopython=True)
def s(A, S, ruiseki, N):
    d = dict()
    d[0, 0] = 1  # left:vale right:count
    for i, a in enumerate(A):
        for (left, right) in sorted(d.keys(), reverse=True):
            if left + a > S:
                continue
            if left + ruiseki[N - i] < S:
                break
            if (left + a, right + 1) in d:
                d[left + a, right + 1] += d[left, right]
            else:
                d[left + a, right + 1] = d[left, right]
    return d


def solve(N: int, S: int, A: "List[int]"):
    A.sort(reverse=True)
    ruiseki = [0]
    for a in A[::-1]:
        ruiseki.append(ruiseki[-1] + a)
    d = s(np.array(A), S, np.array(ruiseki), N)
    ans = 0
    for val, count in d.keys():
        if val != S:
            continue
        ans += d[val, count] * 2 ** (N - count)
        ans %= 998244353
    print(ans)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, S, (A))


if __name__ == '__main__':
    main()