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:
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def RA():return map(int,open(0).read().split())
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in range(base**n):s=[tb//(base**bt)%base for bt in range(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
 
YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
input=lambda: sys.stdin.readline().rstrip()


class Tree:
    def __init__(self,inp_size=None,ls=None,init=True,index=0):
        self.LCA_init_stat=False
        self.ETtable=[]
        if init:
            if ls==None:
                self.stdin(inp_size,index=index)
            else:
                self.size=len(ls)+1
                self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return
 
    def stdin(self,inp_size=None,index=1):
        if inp_size==None:
            self.size=int(input())
        else:
            self.size=inp_size
        self.edges,_=GI(self.size,self.size-1,index=index)
        return
    
    def listin(self,ls,index=0):
        self.size=len(ls)+1
        self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return
 
    def __str__(self):
        return  str(self.edges)
 
    def dfs(self,x,func=lambda prv,nx,dist:prv+dist,root_v=0):
        q=deque()
        q.append(x)
        v=[-1]*self.size
        v[x]=root_v
        while q:
            c=q.pop()
            for nb,d in self.edges[c]:
                if v[nb]==-1:
                    q.append(nb)
                    v[nb]=func(v[c],nb,d)
        return v
 
    def EulerTour(self,x):
        q=deque()
        q.append(x)
        self.depth=[None]*self.size
        self.depth[x]=0
        self.ETtable=[]
        self.ETdepth=[]
        self.ETin=[-1]*self.size
        self.ETout=[-1]*self.size
        cnt=0
        while q:
            c=q.pop()
            if c<0:
                ce=~c
            else:
                ce=c
                for nb,d in self.edges[ce]:
                    if self.depth[nb]==None:
                        q.append(~ce)
                        q.append(nb)
                        self.depth[nb]=self.depth[ce]+1
            self.ETtable.append(ce)
            self.ETdepth.append(self.depth[ce])
            if self.ETin[ce]==-1:
                self.ETin[ce]=cnt
            else:
                self.ETout[ce]=cnt
            cnt+=1
        return
    
    def LCA_init(self,root):
        self.EulerTour(root)
        self.st=SparseTable(self.ETdepth,init_func=min,init_idl=inf)
        #self.st=SegTree(self.size*2-1,self.ETdepth,function=min,ide=inf)
        self.LCA_init_stat=True
        return
    
    def LCA(self,root,x,y):
        if self.LCA_init_stat==False:
            self.LCA_init(root)
        xin,xout=self.ETin[x],self.ETout[x]
        yin,yout=self.ETin[y],self.ETout[y]
        a=min(xin,yin)
        b=max(xout,yout,xin,yin)
        id_of_min_dep_in_et=self.st.query_id(a,b+1)
        return self.ETtable[id_of_min_dep_in_et]

## Tested by EduFor 88 D
## https://codeforces.com/contest/1359/problem/D

class SparseTable: # O(N log N) for init, O(1) for query(l,r)
    def __init__(self,ls,init_func=min,init_idl=float('inf')):
        self.func=init_func
        self.idl=init_idl
        self.size=len(ls)
        self.N0=self.size.bit_length()
        self.table=[ls[:]]
        self.index=[list(range(self.size))]
        self.lg=[0]*(self.size+1)
        
        for i in range(2,self.size+1):
            self.lg[i]=self.lg[i>>1]+1
 
        for i in range(self.N0):
            tmp=[self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) for j in range(self.size)]
            tmp_id=[self.index[i][j] if self.table[i][j]==self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) else self.index[i][min(j+(1<<i),self.size-1)] for j in range(self.size)]
            self.table+=[tmp]
            self.index+=[tmp_id]
    
    # return func of [l,r)
    def query(self,l,r):
        if r>self.size:r=self.size
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        return self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))])
    
    # return index of which val[i] = func of v among [l,r)
    def query_id(self,l,r):
        if r>self.size:r=self.size
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        a,b=self.index[N][l],self.index[N][max(0,r-(1<<N))]
        if self.table[0][a]==self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))]):
            b=a
        return b
    
    # return boundary index of r such that func({table[i]} =< x , i in [pos,r]
    def right_bound(self,pos,x):
        k=(self.size-pos).bit_length()
        for j in range(k)[::-1]:
            nx=pos+(1<<j)
            if nx<n and self.query(pos,nx+1)<=x:
                pos+=(1<<j)
        return pos
    
    # return boundary index of l such that func({table[i]} =< x , i in [l,pos]
    def left_bound(self,pos,x):
        k=pos.bit_length()
        for j in range(k)[::-1]:
            nx=pos-(1<<j)
            if 0<=nx and self.query(nx,pos+1)<=x:
                pos-=(1<<j)
        return pos

    def __str__(self):
        return str(self.table[0])
 
    def print(self):
        for i in self.table:
            print(*i)
 

## return prime factors of N as dictionary {prime p:power of p}
## within 2 sec for N = 2*10**20+7
def primeFactor(N):
    i,n=2,N
    ret={}
    d,sq=2,99
    while i<=sq:
        k=0
        while n%i==0:
            n,k,ret[i]=n//i,k+1,k+1
        if k>0 or i==97:
            sq=int(n**(1/2)+0.5)
        if i<4:
            i=i*2-1
        else:
            i,d=i+d,d^6
    if n>1:
        ret[n]=1
    return ret


## return the list of prime numbers in [2,N], using eratosthenes sieve
## within 2sec for N = 1.2*10**7
def PrimeNumSet(N):
    Max = int(N**0.5)
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList:
        if seachList[0] <= Max:
            break
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum

## retrun LCM of numbers in list b
## within 2sec for no of B = 10*5  and  Bi < 10**6
def LCM(b,mo=10**9+7):
    prs=PrimeNumSet(max(b))
    M=dict(zip(prs,[0]*len(prs)))
    for i in b:
        dc=primeFactor(i)
        for j,k in dc.items():
            M[j]=max(M[j],k)
    
    r=1
    for j,k in M.items():
        if k!=0:
            r*=pow(j,k,mo)
            r%=mo
    return r

 
show_flg=False
show_flg=True
ans=0


n,s=LI()
a=LI()
mo=998244353

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

for i in rep(n):
    for j in range(s+1):
        DP[i+1][j]=DP[i][j][:]
    c=a[i]
    for j in rep(s+1):
        if j+c<=s:
            for k in rep(n):
                if DP[i][j][k]!=0:
                    DP[i+1][j+c][k+1]+=DP[i][j][k]


#for i in range(n+1):
t=DP[n][s]
z=[x*pow(2,n-k,mo) for k,x in enumerate(t)]

ans=sum(z)
print(ans%mo)

Submission status: Time Limit Exceeded

Solution code:
n, s = map(int, input().split())
aa = list(map(int, input().split()))
mod = 998244353
states = [(0,0)]
cnt = 0
for a in aa:
    s_new = []
    for state in states:
        s_new += [state]
        if state[1] + a <s:
            s_new += [(state[0]+1, state[1] + a)]
        elif state[1] + a == s:
            cnt = (cnt + 2**(n-state[0]-1) )%mod
    states = s_new
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import defaultdict
from queue import deque
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


ans = 0


def main():
    N, S = geta(int)
    A = list(geta(int))
    mod = 998244353

    def dfs(n, s, ret):

        global ans

        if s == 0:
            ans = (ans + pow(2, N - ret)) % mod
            return
        if n == 0:
            return

        dfs(n - 1, s - A[n - 1], ret + 1)

        dfs(n - 1, s, ret)

    dfs(N, S, 0)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 998244353

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, S = LI()
    a = LI()
    dp = [[0 for _ in range(S+1)] for _ in range(N+1)]
    for i in range(1, N+1):
        dp[i][0] = dp[i-1][0] * 2 + 1
        dp[i][0] %= mod
    for i in range(N):
        for j in range(1, S+1):
            if j - a[i] >= 0:
                dp[i+1][j] = (dp[i][j-a[i]] % mod) + (dp[i][j] * 2 % mod)
            else:
                dp[i+1][j] = dp[i][j] * 2 % mod
            if j == a[i]:
                dp[i+1][j] += 1
            dp[i+1][j] %= mod
    print(dp[N][S])

main()

Submission status: Time Limit Exceeded

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

mod = 998244353

dp = [[0] * 5000 for _ in range(5000)]

def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x % mod
        x *= x % mod
        n //= 2

    return K * x % mod

pow2 = [1] * (n + 1)
for i in range(n):
    pow2[i + 1] = pow2[i] * 2 % mod
inv2 = pow_k(2, mod - 2)

dp[0][0] = pow2[n]
for i in range(1, n + 1):
    for j in range(s + 1):
        dp[i][j] = dp[i - 1][j]
        if j >= a[i - 1]:
            dp[i][j] = (dp[i][j] + dp[i - 1][j - a[i - 1]] * inv2 % mod) % mod
print(dp[n][s])

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N, S = map(int, input().split())
A = [int(i) for i in input().split()]

mod = 998244353

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

fac = [1]
inv = [1]
for i in range(1, 6010) :
  fac.append(fac[-1] * i % mod)
  inv.append(pow(fac[-1], mod - 2, mod))

def comb(n, r) :
  return fac[n] * inv[r] * inv[n - r] % mod

ret = 0
def dfs(n, s, cnt, pat) :
  if n == -1 :
    if s == S :
      global ret
      ret += pow(2, N - cnt, mod) * pat
      ret %= mod
    return
  for i in range(C[n][1] + 1) :
    if s + C[n][0] * i <= S :
      dfs(n - 1, s + C[n][0] * i, cnt + i, pat * comb(C[n][1], i) % mod)
  
dfs(len(C) - 1, 0, 0, 1)

print(ret)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations


def main():
    n, s = [int(x) for x in input().split()]
    mod = 998244353
    array = [int(x) for x in input().split()]
    index = [x for x in range(n)]
    i_could = []
    for r in range(1, n + 1):
        for ids in combinations(index, r):
            if sum(array[i] for i in ids) == s:
                i_could.append(ids)
    # patterns = [pow(2, x) for x in range(0, n + 1)]
    ans = 0
    for i in i_could:
        ans += pow(2, n - len(i), 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,a-1,-1):
                for ls,val in dp[s-a].items():
                    dp[s][ls+1]=(dp[s].get(ls+1,0)+dp[s-a][ls])%mod
    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:
N, S = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353

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

Pre[0][0].append(0)

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

print(ans % mod)

Submission status: Time Limit Exceeded

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

note = [[0 for i in range(S+1)] for n in range(N+1)]

for n in range(1,N+1):
  for i in range(1,S+1):
    if A[n]>i:
      note[n][i] = (note[n-1][i]*2) % mod
    elif A[n] == i:
      note[n][i] = note[n-1][i]*2 + pow(2,n-1,mod)
      note[n][i] = note[n][i] % mod 
    else:
      note[n][i] = note[n-1][i] * 2 + note[n-1][i-A[n]]
      note[n][i] = note[n][i] % mod
  #print(note)
print(note[N][S] % mod)

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)]
dp[0][0] = 1

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

cnt = 0
K = dp[-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:
N, S = map(int, input().split())
A = list( map( int,input().split() ) )
base = 998244353

# DP-table : [#Ele.][Sum]
dp = [[0 for j in range(S+1)] for i in range(N+1)]

#Initialize:
dp[0][0] = 1

for i in range(N):#Each A[i]
  temp = [[0 for k in range(S+1)] for j in range(N+1)]
  #Pick A[i]
  for j in range(i+1):
    for k in range(S+1):
      if k + A[i] <= S:
        temp[j+1][k + A[i]] += dp[j][k]

  for j in range(i+2):
    for k in range(S+1):
        dp[j][k] += temp[j][k]
        

# for [i][S]
ans = 0
for i in range(1, N+1):
  temp = pow(2, N-i, mod=base) * dp[i][S]
  temp %= base
  ans += temp
  ans %= base
print(ans)

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()]
    a.sort(reverse=True)
    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 and a[i]+j <= s:
                for k, v in dp[j].items():
                    if k+1 in dp[a[i]+j]:
                        dp[a[i]+j][k+1] = (v+dp[a[i]+j][k+1])%mod
                    else:
                        dp[a[i]+j][k+1] = v%mod
            if j == 0 and a[i] <= s:
                if 1 in dp[a[i]]:
                    dp[a[i]][1] = (dp[a[i]][1]+1)%mod
                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:
#!/usr/bin/env python3
import bisect
import collections
import sys
from typing import Tuple, Dict

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

MOD = 998244353  # type: int
import numpy
import numba


@numba.njit(cache=True)
def s(A: numpy.array, S: int, N: int):
    d: Dict[Tuple[int, int], int] = dict()
    ans = 0
    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]
    for val, count in d:
        if val != S:
            continue
        ans += d[val, count] * 2 ** (N - count)
        ans %= 998244353
    return ans


def solve(N: int, S: int, A: "List[int]"):
    A.sort()
    print(s(numpy.array(A), S, N))


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:
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):
        if sum(c)==s:
            sub.append(c)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import setrecursionlimit

setrecursionlimit(200000)

mod = 998244353
o = [0] * 34

def bi(x):
    global o
    o = [0] * 34
    i = 0
    while x != 0:
        o[i] = x%2
        x //= 2
        i += 1

def modpow(m,n):
    global mod,o
    bi(n)
    b = 1
    p = m
    for i in range(34):
        if i:
            p = (p * p)%mod
        if o[i]:
            b *= p
            b %= mod
    return b

# ナップサックDPで経路復元ができたとして
# 経路長がkである経路2^(N-k)の総和を求める

N,S = map(int,input().split())
A = list(sorted(map(int,input().split()),reverse=True))
DP = [[0]*(S+1) for x in range(N+1)]

DP[0][0] = 1
su = 0
for i in range(1,N+1):
    su += A[i-1]
    for j in range(0,min(su+1,S+1)):
        if j + A[i-1] < S+1:
            DP[i][j+A[i-1]] += DP[i-1][j]
        DP[i][j] += DP[i-1][j]

ans = 0

keiro = 0
def rec(i,j):
    global keiro,DP,ans
    if DP[i][j] == 0:
        return
    if i == 0:
        #print(keiro)
        ans += modpow(2,N-keiro)
        ans %= mod
        return
    if j - A[i-1] >= 0:
        #keiro.append((A[i-1],i-1))
        keiro += 1
        rec(i-1,j-A[i-1])
        #keiro.pop()
        keiro -= 1
    rec(i-1,j)

rec(N,S)

#print(*DP)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,S=map(int,input().split())
A=list(map(int,input().split()))
dp=[[0 for i in range(S+1)]for j in range(N+1)]
dp[0][0]=1
for i in range(N):
    for j in range(S+1):
        if j-A[i]>=0:
            dp[i+1][j]+=dp[i][j-A[i]]+2*dp[i][j]
        else:
            dp[i+1][j]+=2*dp[i][j]
print(dp[N][S]%998244353)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

LI = lambda: list(map(int, input().split()))

n, s = LI()
a = LI()
dp = np.zeros((n+1, s+1), dtype=np.int)
dp[0][0] = 1

for i in range(n):
    for w in range(s+1):
        dp[i+1][w] = 2*dp[i][w]
        if w >= a[i]:
            dp[i+1][w] += dp[i][w-a[i]]
        dp[i+1][w] %= 998244353

print(dp[n][s])

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)
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:
        x=n-sum(b)-1
        y=1
        for i in range(x):
            y*=2
            y=y%998244353
        ans+=y
        ans=ans%998244353
        now+=1
    else:
        now+=1
        
print(ans)

Submission status: Time Limit Exceeded

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

MOD=998244353

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

#DP[i][j]:i個の数の組み合わせでjを作れる組みの数
DP=[[0]*(S+1) for _ in range(N+1)]

DP[0][0]=1

for a in A:
    for cur_val in reversed(range(S)):
        if a+cur_val>S:
            continue
        for cur_num in reversed(range(N)):
            DP[cur_num+1][a+cur_val]+=DP[cur_num][cur_val]



ans=0
for i in range(N+1):
    val = DP[i][S]
    ans+= val*pow(2,N-i,MOD)
    ans%=MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,S=map(int,input().split())
A=list(map(int,input().split()))
dp=[[0 for i in range(S+1)]for j in range(N+1)]
# dp[0]=[-1 for i in range(S)]
dp[0][0]=1
for i in range(N):
    for j in range(S+1):
        if j-A[i]>=0:
            dp[i+1][j]+=dp[i][j-A[i]]+2*dp[i][j]
        else:
            dp[i+1][j]+=2*dp[i][j]
print(dp[N][S]%998244353)

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 i in range(N + 1)]
DP[0][0] = 1
for i in range(N):
  for j in range(S + 1):
    if j >= A[i]:
      DP[i + 1][j] = (DP[i][j] * 2 + DP[i][j - A[i]]) % MOD
    else:
      DP[i + 1][j] = (DP[i][j] * 2) % MOD

print(DP[-1][-1] % 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()))

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)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import bisect
import collections
import sys
from typing import Tuple, Dict

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

MOD = 998244353  # type: int
import numpy


def s(A: numpy.array, S: int, N: int):
    d: Dict[Tuple[int, int], int] = dict()
    ans = 0
    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]
    for val, count in d:
        if val != S:
            continue
        ans += d[val, count] * 2 ** (N - count)
        ans %= 998244353
    return ans


def solve(N: int, S: int, A: "List[int]"):
    A.sort()
    print(s(numpy.array(A), S, N))


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
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])%mod
    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:
n, s = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
mod = 998244353
ans = 0

a_cum = [0 for _ in range(n+1)]
for i in range(n):
    a_cum[i+1] = a_cum[i] + a[i]
#print(a_cum)
dp = [[{} for _ in range(n+1)] for _ in range(n+1)]
dp[0][0] = {0: 1}

for i in range(n):
    for j in range(i+1):
        for k in dp[i][j].keys():
            if k in dp[i+1][j]:
                dp[i+1][j][k] += dp[i][j][k]
            else:
                dp[i+1][j][k] = dp[i][j][k]

            if k + a[i] <= s:
                if k+a[i] in dp[i+1][j+1]:
                    dp[i+1][j+1][k+a[i]] += dp[i][j][k]
                else:
                    dp[i+1][j+1][k+a[i]] = dp[i][j][k]


for j in range(n+1):
    if s in dp[n][j]:
        ans = (ans + dp[n][j][s] * pow(2, n-j, mod) % mod) % mod

print(ans)