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: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

import copy

N,S = IL()
A = IL()

dic = DD(lambda: DD(int))
dic[0] = DD(int)
dic[0][0] = 0

for a in A:
  koushinyotei = []
  for s,subdic in dic.items():
    if s+a <= S:
      for n in subdic.keys():
        koushinyotei.append((s+a,n+1))
  for s,n in koushinyotei:
    dic[s][n] += 1

ans = 0
ansdic = dic[S]
for n,a in ansdic.items():
  print(n,a)
  ans += pow(2,N-n,998244353)*a
  ans %= 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
mod = 998244353

def solve():
    input = sys.stdin.readline
    N, S = map(int, input().split())
    A = [int(a) for a in input().split()]
    DP = [[[] for _ in range(S + 1)] for i in range(N)]
    DP[0][0].append(0)
    if A[0] <= S: DP[0][A[0]].append(1)
    ans = 0
    for i, a in enumerate(A[1:]):
        for s in range(S):
            for key in DP[i][s]:
                DP[i+1][s].append(key)
                if s + a < S: DP[i+1][s+a].append(key + 1)
                elif s + a == S: 
                    ans += pow(2, N - key - 1, mod)
                    ans %= mod
    print(ans)


    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

Solution code:
def main():
    N, S = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    mod = 998244353
    n = len(A)
    l = [[0] * (N+1) for _ in range(S+1)]
    if A[0] > S:
        return 0
    l[A[0]][1] = 1
    for i in range(1, N):
        if A[i] > S:
            continue
        for j in range(S, A[i]-1, -1):
            for k in range(1, N+1):
                l[j][k] += l[j-A[i]][k-1]
        l[A[i]][1] += 1
    r = 0
    for i in range(N):
        r += pow(2, N-i, mod) * l[-1][i]
        r %= mod
    return r
print(main())

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(5000)
MOD=998244353
def dfs(d,tot,num):
    global A,N,S,how
    if tot==S:
        how[num]+=1
        return
    if d==N:
        return
    if tot+A[d]<=S:
        dfs(d+1,tot+A[d],num+1)
    dfs(d+1,tot,num)
        
    

N,S=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
how=[0]*(N+1)
dfs(0,0,0)
cur=1
res=0
for i in range(N,0,-1):
    res+=how[i]*cur%MOD
    cur*=2
print(res)

Submission status: Wrong Answer

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(sub)

Submission status: Wrong Answer

Solution code:
MOD = 998244353


def main():
    from itertools import accumulate
    import sys
    sys.setrecursionlimit(10**6)
    N, S = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    A.sort(reverse=True)
    acc = list(accumulate([0] + A))
    depth = set()

    def dfs(i, v):
        if i == N:
            if v == S:
                depth.add(i)
                return 1
            else:
                return 0
        if v == S:
            depth.add(i)
            return 2**(N-i)
        if S < v or v + (acc[N] - acc[i]) < S:
            return 0
        res = 0
        res += dfs(i+1, v + A[i]) + dfs(i+1, v)
        return res % MOD

    ans = dfs(0, 0) % MOD
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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]]
    else:
      DP[i + 1][j] = DP[i][j] * 2

print(DP[-1][-1])

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(5000)

def dfs(d,tot,num):
    global A,N,S,how
    if tot==S:
        how[num]+=1
        return
    if d==N:
        return
    if tot+A[d]<=S:
        dfs(d+1,tot+A[d],num+1)
    dfs(d+1,tot,num)
        
    

N,S=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
how=[0]*(N+1)
dfs(0,0,0)
cur=1
res=0
for i in range(N,0,-1):
    res+=how[i]*cur
    cur*=2
print(res)

Submission status: Wrong Answer

Solution code:
n,s = map(int,input().split())
a = list(map(int,input().split()))
dp = [[0 for _ in range(s+1)] for _ in range(n+1)]

mod = 998244353

def power(n,e):
    ret = 1
    b = n
    while e:
        if e % 2 != 0:
            ret *= b
        ret %= mod
        b *= b
        b %= mod
        e //= 2
    return ret

def div(n1,n2):
    return n1*power(n2,mod-2)%mod

dp[0][0] = power(2,n)
for i in range(1,n+1):
    for j in range(s+1):
        dp[i][j] = dp[i-1][j]
    for j in range(s+1):
        if j >= a[i-1]:
            dp[i][j] += div(dp[i-1][j-a[i-1]],2)

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

Submission status: Wrong Answer

Solution code:
n,s = map(int,input().split())
a = list(map(int,input().split()))
if n == 1:
    if a[0] == s:
        print(1)
        quit()
    else:
        print(0)
        quit()

mod = 998244353
dp = [[0]*(s+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(n):
    dp[i+1][0] = 2*dp[i][0]%mod
    for j in range(s+1):
        dp[i+1][j] = dp[i][j]*2%mod
    if a[i] <= s:
        for j in range(a[i],s+1):
            dp[i+1][j] += dp[i][j-a[i]]
print(dp[-1][-1])

Submission status: Wrong Answer

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)]
dp[0][0] = 1
for i in range(n):
    dp[i+1][0] = 2*dp[i][0]%mod
    for j in range(s+1):
        dp[i+1][j] = dp[i][j]*2%mod
    if a[i] <= s:
        for j in range(a[i],s+1):
            dp[i+1][j] += dp[i][j-a[i]]
print(dp[-1][-1])

Submission status: Wrong Answer

Solution code:
import sys
from collections import OrderedDict
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


def inpl():
    return list(map(int, input().split()))


def main():
    MOD = 998244353
    N, S = inpl()
    A = sorted(inpl())
    dp = [OrderedDict() for _ in range(N + 1)]
    dp[0][0] = 1
    for i, a in enumerate(A):
        for j in range(min(S - a, i), -1, -1):
            for k, v in dp[j].items():
                if k + a > S:
                    break
                if k + a not in dp[j + 1]:
                    dp[j + 1][k + a] = v
                else:
                    dp[j + 1][k + a] = v + dp[j + 1][k + a]
    # print(dp)

    p2 = [0] * (N + 1)
    p2[0] = 1
    for i in range(1, N + 1):
        p2[i] = (p2[i - 1] * 2) % MOD

    ans = 0
    for i in range(1, N + 1):
        if S in dp[i]:
            ans = (ans + dp[i][S] * p2[N - i]) % MOD
    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 998244353
N, S = lr()
A = lr()
dp = np.zeros((N+1, S+1), np.int32)  # dp[i][j]はi個選んだ合計jの個数
dp[0][0] = 1
for a in A:
    for i in range(N-1, -1, -1):
        dp[i+1][a:] += dp[i][:-a]

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)

MOD = 998244353  # type: int

INV = pow(2, MOD - 2, MOD)

def calc_fraction_mod(numerator):
    '''
        returns numerator / denominator (mod MOD)
    '''
    #inv = pow(denominator, MOD - 2, MOD)
    return numerator * INV % MOD


def solve(N: int, S: int, A: "List[int]"):
    A.sort()
    dp = [0] * (S + 1)
    dp[0] = pow(2, N, MOD)
    for i, a in enumerate(A):
        for s in range(S + 1)[::-1]:
            if dp[s] == 0:
                continue
            if s + a <= S:
                dp[s + a] += calc_fraction_mod(dp[s])
    print(dp[S])
    #ret = 0
    #print(ret)

def solve_(N: int, S: int, A: "List[int]"):
    A.sort()
    dp = [[0] * (S + 1) for _ in range(N + 1)]
    dp[0][0] = 1
    for i in range(N):
        a = A[i]
        for s in range(S + 1)[::-1]:
            if s + a <= S:
                pass
                #dp[
    ret = 0
    print(ret)
    return

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: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)

MOD = 998244353  # type: int

def calc_fraction_mod(numerator, denominator):
    '''
        returns numerator / denominator (mod MOD)
    '''
    inv = pow(denominator, MOD - 2, MOD)
    return numerator * inv % MOD


def solve(N: int, S: int, A: "List[int]"):
    ps = []
    for i in range(N + 1):
        ps.append(pow(2, i, MOD))
    A.sort()
    dp = [0] * (S + 1)
    dp[0] = ps[N]
    for i, a in enumerate(A):
        for s in range(S + 1)[::-1]:
            if dp[s] == 0:
                continue
            if s + a <= S:
                dp[s + a] += calc_fraction_mod(dp[s], 2)
    print(dp[S])
    #ret = 0
    #print(ret)

def solve_(N: int, S: int, A: "List[int]"):
    A.sort()
    dp = [[0] * (S + 1) for _ in range(N + 1)]
    dp[0][0] = 1
    for i in range(N):
        a = A[i]
        for s in range(S + 1)[::-1]:
            if s + a <= S:
                pass
                #dp[
    ret = 0
    print(ret)
    return

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: Wrong Answer

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

al = list(map(int,input().split()))

ans = 0
dp = [0 for _ in range(s + 1)]
dp[0] = 1
for i in range(n):
    for k in range(s, -1, -1):
        if k - al[i] < 0:
            dp[k] = 2 * dp[k]
        else:
            dp[k] = 2 * dp[k] + dp[k-al[i]]


print(dp[-1])

Submission status: Wrong Answer

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

L = [[0 for i in range(S+1)] for j in range(N+1)]
L[0][0] = 1
for j, a in enumerate(A):
  for i in range(S+1):
    if i < a:
      L[j+1][i] = 2 * L[j][i]
    else:
      L[j+1][i] = 2 * L[j][i] + L[j][i-a]
print(L[N][S])

Submission status: Wrong Answer

Solution code:
N,S = map(int,input().split())
A = list(map(int,input().split()))
dp = [[[] for i in range(S+1)] for i in range(N+1)]
dp[0][0].append(0)
for i in range(1,N+1):
    a = A[i-1]
    for j in range(S-a+1):
        if len(dp[i-1][j]) != 0:
            for k in dp[i-1][j]:
                dp[i][j+a].append(k+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

mod = 998244353

def modinv(x, m = mod):
    b = m
    u = 1
    v = 0
    while b:
        t = x // b
        x -= t * b
        x, b = b, x
        u -= t * v
        u, v = v, u
    u %= m
    if u < 0:
        u += m
    return u

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

    pow2 = [0 for _ in range(n+1)]
    pow2[0] = 1
    for i in range(n):
        pow2[i+1] = (pow2[i] * 2) % mod

    ans = 0
    dp = [0 for _ in range(s+1)]
    dp[0] = pow2[n]
    for i in range(n):
        dp_next = [0 for _ in range(s+1)]
        for j in range(s+1):
            dp_next[j] += (dp[j]) % mod
            if j + a[i] <= s:
                dp_next[j+a[i]] += (dp[j] * modinv(2)) % mod
        dp = dp_next

    print(dp[s])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
mod = 998244353
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):
        dp[i+1][j] += dp[i][j] * 2
        if j + A[i] <= S:
            dp[i+1][j+A[i]] += dp[i][j]

print(dp[N][S])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

dp = [0]*(S+1)
dp[0] = 1
for a in A:
    ndp = [0]*(S+1)
    for total,cnt in enumerate(dp):
        ndp[total] += (dp[total]*2)%MOD
        if total+a <= S:
            ndp[total+a] += dp[total]
            ndp[total+a] %= MOD
    dp = ndp

print(dp[-1])

Submission status: Wrong Answer

Solution code:
from math import factorial as fac
from functools import lru_cache

n, s = map(int, input().split())
l = [int(i)for i in input().split()]
l.sort(reverse=True)
mod = 998244353

z = 0


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


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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

n, s, *aaa = map(int, sys.stdin.buffer.read().split())
MOD = 998244353

dp = np.zeros(s + 1, np.int64)
dp[0] = 1

for a in aaa:
    ndp = dp * 2 % MOD
    if a <= s:
        ndp[a:] += dp[:-a]
        dp = ndp % MOD

print(dp[s])

Submission status: Wrong Answer

Solution code:
a,b=map(float,input().split())
a=int(a)
print(int(a*b))

Submission status: Wrong Answer

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

def dpinit(ps, val=0):
    res = [val for i in [0]*ps[-1]]
    for i in ps[:-1][::-1]:
        res = [res[:] for k in [0]*i]
    return res

dp = dpinit((N+1,S+1))

dp[0][0] = 1
for i in range(N):
    a = A[i]
    for j in range(S+1):
        dp[i+1][j] += dp[i][j]*2
        if j+a <= S:
            dp[i+1][j+a] += dp[i][j]

print(dp[N][S])

Submission status: Wrong Answer

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)]

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

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

Submission status: Wrong Answer

Solution code:
from math import factorial as fac

n, s = map(int, input().split())
l = [int(i)for i in input().split()]
mod = 998244353

z = 0


def f(i, tot, nn):
    # print(st)
    #print(i, tot, nn)
    global z
    if tot > s:
        return
    elif tot == s:
        print(i, tot, nn)
        z += 2 ** (n - nn)
        z %= mod
    elif i == n:
        return
    else:
        for j in range(i, n):
            f(j + 1, tot + l[j], nn + 1)


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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

n, s, *aaa = map(int, sys.stdin.buffer.read().split())
MOD = 998244353
dp = np.zeros(s + 1, np.int64)
dp[0] = 1

for a in aaa:
    ndp = dp * 2 % MOD
    if a > s:
        continue
    ndp[a:] += dp[:-a]
    dp = ndp % MOD

print(dp[s])

Submission status: Wrong Answer

Solution code:
dp = [[0]*3001 for _ in range(3001)]
n,s = (int(num) for num in input().split())
a = [int(num) for num in input().split()]
dp[0][0] = 1
for i in range(1,n+1):
    for j in range(s+1):
        dp[i][j] = dp[i-1][j] * 2
        if j >= a[i-1]:
            dp[i][j] += dp[i-1][j-a[i-1]]
            
print(dp[n][s])

Submission status: Wrong Answer

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
mod = 10**9+7
for i in range(1,n+1):
  x = a[i-1]
  for j in range(s+1):
    dp[i][j] += dp[i-1][j]*2
    dp[i][j] %= mod
  for j in range(x,s+1):
    dp[i][j] += dp[i-1][j-x]
    dp[i][j] %= mod
print(dp[-1][-1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

dp = [Counter() for _ in range(S + 1)]
dp[0][0] = 1

for a in A:
    for s in range(S + 1)[::-1]:
        if s + a <= S:
            for n, cnt in dp[s].items():
                dp[s + a][n + 1] += cnt
                dp[s + a][n + 1] %= MOD

ans = 0
for n, cnt in dp[S].items():
    k = pow(2, N - n)
    ans = (ans + k * cnt) % MOD
print(-1)