Problem:


Score : 200 points

Problem Statement

There are N bags of biscuits. The i-th bag contains A_i biscuits.

Takaki will select some of these bags and eat all of the biscuits inside.
Here, it is also possible to select all or none of the bags.

He would like to select bags so that the total number of biscuits inside is congruent to P modulo 2.
How many such ways to select bags there are?

Constraints

1 \leq N \leq 50

P = 0 or 1

1 \leq A_i \leq 100

Input

Input is given from Standard Input in the following format:

N P
A_1 A_2 ... A_N

Output

Print the number of ways to select bags so that the total number of biscuits inside is congruent to P modulo 2.

Sample Input 1

2 0
1 3

Sample Output 1

2

There are two ways to select bags so that the total number of biscuits inside is congruent to 0 modulo 2:

Select neither bag. The total number of biscuits is 0.

Select both bags. The total number of biscuits is 4.

Sample Input 2

1 1
50

Sample Output 2

0

Sample Input 3

3 0
1 1 1

Sample Output 3

4

Two bags are distinguished even if they contain the same number of biscuits.

Sample Input 4

45 1
17 55 85 55 74 20 90 67 40 70 39 89 91 50 16 24 14 43 24 66 25 9 89 71 41 16 53 13 61 15 85 72 62 67 42 26 36 66 4 87 59 91 4 25 26

Sample Output 4

17592186044416



Sample input:
2 0
1 3


Sample output:
2

Submission status: Accepted

Solution code:
n,p=map(int,input().split())
l=list(map(int,input().split()))
o=sum(1 for i in l if i%2==1)
e=len(l)-o
if o==0:
  if p==0:print(2**n)
  else:print(0)
else:
  print(2**(n-1))

Submission status: Accepted

Solution code:
N, P = map(int, input().split()) # 横に2個
A = [0 if a % 2 == 0 else 1 for a in list(map(int, input().split()))]
odd = A.count(1)
even = A.count(0)

if (P == 1 and odd == 0 ):
    ans = 0
elif odd == 0:
    ans = 2**(len(A))
else:
    ans = 2**(len(A)-1)

print(ans)

Submission status: Accepted

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

odd = 0
even = 0
for a in A:
    if a % 2 == 0:
        even += 1
    else:
        odd += 1

if odd == 0:
    if P % 2 == 0:
        print(2 ** N)
    else:
        print(0)
else:
    print(2 ** (N - 1))

Submission status: Accepted

Solution code:
import math
from collections import Counter
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N, P = map(int, input().split())
A = [int(i)%2 for i in input().split()]
m = Counter(A)
num0 = m[0]
num1 = m[1]
num = 0
if P == 0:
    for i in range(num1+1):
        if i%2 == 0:
            num += combinations_count(num1, i)
    print((2**num0)*num)
else:
    for i in range(num1+1):
        if i%2 == 1:
            num += combinations_count(num1, i)
    print((2**num0)*num)

Submission status: Accepted

Solution code:
N,P = map(int,input().split())
A = [int(i)%2 for i in input().split()]

odd = sum(A)
even = N - odd
import math

def Comb(a,b):#aCbを返す
    if a>= b:
        return int(math.factorial(a)/(math.factorial(b)*math.factorial(a-b)))
    else:
        return 0
if P == 0:
    ans = 2**N
    for i in range(1,odd+1,2):
        ans -= Comb(odd,i)*(2**even)
    print(ans)
else:
    ans = 0
    for i in range(1,odd+1,2):
        ans += Comb(odd,i)*(2**even)
    print(ans)

Submission status: Accepted

Solution code:
N, P = map(int, input().split())
A = [int(i) for i in input().split()]

e = 0
o = 0
for a in A:
    if a % 2 == 0:
        e += 1
    else:
        o += 1

if P == 1:
    print((2**e)*((2**o)//2))
else:
    print(2**N-(2**e)*((2**o)//2))

Submission status: Accepted

Solution code:
n, p = map(int, input().split())
a = list(map(int, input().split()))
zc = 0
oc = 0
for i in range(n):
    a[i] %= 2
    if a[i]:
        oc += 1
    else:
        zc += 1


def comb(x, y):
    if y < 0 or y > x or x < 0:
        return 0
    ret = 1
    for i in range(1, y+1):
        ret *= x+1-i
        ret //= i
    return ret


ans = 0
for i in range(p, oc+1, 2):
    ans += comb(oc, i)
print(ans*2**zc)

Submission status: Accepted

Solution code:
n,p = map(int,input().split())
an = [int(i) for i in input().split()]
x = 0
for i in an:
  x |= i%2
if x:
  print(2**(n-1))
else:
  if p:
    print(0)
  else:
    print(2**n)

Submission status: Accepted

Solution code:
n,p = map(int,input().split())
an = [int(i) for i in input().split()]
dpo = [0]*n
dpe = [0]*n

if an[0] % 2 == 0:
  dpe[0] = 2
else:
  dpo[0] = 1
  dpe[0] = 1
  
for i in range(1,n):
  if an[i] % 2 == 0:
    dpe[i] = dpe[i-1] * 2
    dpo[i] = dpo[i-1] * 2
  else:
    dpe[i] = dpe[i-1] + dpo[i-1]
    dpo[i] = dpo[i-1] + dpe[i-1]
if p:
  print(dpo[n-1])
else:
  print(dpe[n-1])

Submission status: Accepted

Solution code:
import math

n, p = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

o_cnt = 0
e_cnt = 0

for i in range(n):
    if a[i] % 2 == 1:
        o_cnt += 1
    else:
        e_cnt += 1

ans = 0
for i in range(o_cnt//2):
    ans += (math.factorial(o_cnt)//(math.factorial(i*2+p)*math.factorial(o_cnt-i*2-p)))*2**e_cnt
    if i == o_cnt//2-1:
        if p == 0:
            ans += (math.factorial(o_cnt)//(math.factorial((i+1)*2+p)*math.factorial(o_cnt-(i+1)*2-p)))*2**e_cnt
        print(ans)

if o_cnt == 0:
    if p == 0:
        print(2**e_cnt)
    else:
        print(0)

Submission status: Accepted

Solution code:
from math import factorial as f
n,p=map(int,input().split())
a=[i%2 for i in list(map(int,input().split()))]
e=a.count(0);o=a.count(1)
def c(x,y):
    return f(x)//(f(x-y)*f(y))
v=0
for i in range(e+1):
  v+=c(e,i)
w=0
t=0 if p==0 else 1
for i in range(t,o+1,2):
  w+=c(o,i)
print(v*w)

Submission status: Accepted

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

for i in range(n):
    A[i]%=2
zero=A.count(0)
if zero==n and p==0:
    print(2**n)
elif zero==n and p==1:
    print(0)
else:
    print(2**(n-1))

Submission status: Accepted

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

odd = 0 # 奇数
even = 0

for a in A:
    if a % 2:
        odd += 1
    else:
        even += 1

if odd == 0:
    if P == 1:
        print(0)
    else:
        print(2 ** N)
else:
    print(2 ** (N - 1))

Submission status: Accepted

Solution code:
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N,P = [int(x) for x in input().split()]
A = [int(x)%2 for x in input().split()]
cnt_odd = 0
cnt_even = 0
cnt = 0
for i in A:
    if(i==1):
        cnt_odd+=1
    else:
        cnt_even+=1
if(cnt_odd==0):
    if(P==1):
        print(0)
    else:
        print(1<<cnt_even)
else:
    i = 0
    while(cnt_odd>=i*2+P):
        cnt+=combinations_count(cnt_odd,i*2+P)*(1<<cnt_even)
        i+=1
    print(cnt)

Submission status: Accepted

Solution code:
def combination(n, r):
    r = min(r, n-r)
    tmp = 1
    for i in range(r):
        tmp *= (n-i)
    for i in range(r):
        tmp //= (i+1)
    return tmp


def main():
    N, P = map(int, input().split())
    A = list(map(int, input().split()))
    odds = 0
    for a in A:
        if a % 2 == 1:
            odds += 1
    ans = 0
    for i in range(P, odds+1, 2):
        ans += combination(odds, i)
    ans *= 2**(N-odds)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,p,*a=map(int,open(0).read().split());print(2**~-n*any(b&1for b in a)or(1^p)*2**n)

Submission status: Accepted

Solution code:
n,p=map(int,input().split())
a=list(map(int,input().split()))
odd=0
even=0
for x in a:
    if x%2==0:
        even+=1
    else:
        odd+=1
if p==0:
    print(2**even*max(1,2**(odd-1)))
else:
    print(2**even*(2**odd-max(2**(odd-1),1)))

Submission status: Accepted

Solution code:
N, P = map(int, input().split())
*A, = map(int, input().split())
even = 0
for a in A:
    if a % 2 == 0:
        even += 1
if even == N:
    print(2**N if P == 0 else 0)
else:
    print(2**(N-1))

Submission status: Accepted

Solution code:
from functools import reduce

def binom(n, r):
    if n < r or n < 0 or r < 0: return 0
    
    if n - r < r: r = n - r
    if r == 0: return 1
    elif r == 1: return n

    numerator = [n - r + 1 + k for k in range(r)]  # (n-r+1)*(n-r+2)*...*(n-1)*n
    denominator = [1+ k for k in range(r)]         # 1*2*...*(r-1)*r

    # reduce prod(numerator)//prod(denominator)
    for p in range(2, r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1, r, p):
                numerator[k - offset] //= pivot
                denominator[k] //= pivot
    
    # calculate nCr
    return reduce(lambda x, y: x*y, numerator)

N, P = map(int, input().split())
*A, = map(int, input().split())
even = 0; odd = 0;
for a in A:
    if a % 2 == 0:
        even += 1
    else:
        odd += 1
ans = 2**even
temp = 0
if P == 0:
    for i in range(0, odd+1, 2):
        temp += binom(odd, i)
else:
    for i in range(1, odd+1, 2):
        temp += binom(odd, i)
ans *= temp
print(ans)

Submission status: Accepted

Solution code:
from math import factorial

def comb(m, n):
    return factorial(m) // factorial(n) // factorial(m-n)

def solve(n, p, a):
    n_odd = len(list(filter(lambda _:_%2, a)))
    n_even = n - n_odd
    v = 2**n_even
    w = sum([comb(n_odd, k) for k in range(p, n_odd+1, 2)])
    return v * w

n, p = map(int, input().split())
a = list(map(int, input().split()))
print(solve(n, p, a))

Submission status: Accepted

Solution code:
from math import factorial

def comb(m, n):
    return factorial(m) // factorial(n) // factorial(m-n)

def solve(n, p, a):
    n_odd = len(list(filter(lambda _:_%2, a)))
    n_even = n - n_odd
    v = 2**n_even
    w = sum([comb(n_odd, k) for k in range(p, n_odd+1, 2)])
    return v * w

n, p = map(int, input().split())
a = list(map(int, input().split()))
print(solve(n, p, a))

Submission status: Accepted

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

for i in range(n):
    a[i]%=2

a1 = a.count(1)
a0 = a.count(0)

if a1>0:
    print(2**a0*2**(a1-1))
else:
    if p == 1:
        print(0)
    else:
        print(2**a0)

Submission status: Accepted

Solution code:
N,P = map(int,input().split())
A = [int(x) for x in input().split()]

odd = sum(x&1 for x in A)

if odd:
  # どちらも半分ずつ
  answer = 2**(N-1)
else:
  answer = (2 ** N) * (1-P)

print(answer)

Submission status: Accepted

Solution code:
n,p = map(int,input().split())
a = list(map(int,input().split()))
even=True
for i in range(n):
    if a[i]%2!=0:
        even=False
        break
if even:
    if p==0:
        ans = 2**n
    else:
        ans = 0
else:
    ans = 2**(n-1)
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
from scipy.misc import comb
import numpy as np
N,P = [int(x) for x in stdin.readline().rstrip().split()]
data = [int(x) for x in stdin.readline().rstrip().split()]
even = 0
odd  = 0
for i in data:
    if i % 2 == 0:
        even += 1
    else:
        odd  += 1
ans = 0
if P == 0:
    for j in range(0,odd+1,2):
        ans += (comb(odd,j,exact=True) * 2 ** even)
else:
    for j in range(1,odd+1,2):
        ans += (comb(odd,j,exact=True) * 2 ** even)

print(ans)

Submission status: Accepted

Solution code:
import math
n, p = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]
odd = 0; even = 0
for item in a:
    if item % 2 == 0:
        even += 1
    else:
        odd += 1
if p == 0:
    ans = 1
    for i in range(1, odd // 2 + 1):
        ans += math.factorial(odd) // math.factorial(i*2) // math.factorial(odd - i * 2)
    print(pow(2,even) * ans)
elif p == 1:
    ans = 0
    for i in range(odd // 2):
        ans += math.factorial(odd) // math.factorial(i*2 + 1) // math.factorial(odd - (i * 2 + 1))
    print(pow(2,even) * ans)

Submission status: Accepted

Solution code:
num_bags, congr_factor = list(map(int, input().split()))
bags = list(map(int, input().split()))
odd_bags = len([bag for bag in bags if (bag % 2 == 1)])

if congr_factor == 0 and odd_bags == 0:
  print(2 ** num_bags)
elif congr_factor == 1 and odd_bags == 0:
  print(0)
else:
  print(2 ** (num_bags-1))

Submission status: Accepted

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

for i in a:
    if i%2 == 1:
        print(2**(n-1))
        exit()
print(0 if p == 1 else 2**n)

Submission status: Accepted

Solution code:
import numpy as np
from math import factorial
n,p=map(int,input().split())
l=np.asarray(list(map(int,input().split())))
l%=2
o=np.sum(l)
e=n-o
def comb(n,r):
    return factorial(n)//factorial(n-r)//factorial(r)
ans=0
for i in range(p,o+1,2):
    ans+=comb(o,i)*(2**e)
print(ans)

Submission status: Accepted

Solution code:
n,p=map(int,input().split())
a=[int(i)%2 for i in input().split()]

c0=a.count(0)
c1=n-c0

def c(n,m):
    import math
    if n-m<0:
        return 0
    return(math.factorial(n)//math.factorial(n-m)//math.factorial(m))

q=0
for i in range(c0+1):
    q+=c(c0,i)


i=p
ans=0
while i<=c1:
    ans+=c(c1,i)*q
    i+=2
print(ans)

Submission status: Accepted

Solution code:
n,p = map(int,input().split())
t = sum([t%2 for t in list(map(int,input().split()))])
if p == 0 and t == 0:
  k = 1
else:
  k = int(2**(t-1))
print(2**(n-t)*k)

Submission status: Accepted

Solution code:
n,p=map(int,input().split())
a=list(map(int,input().split()))
o=0
for i in a:
    if i%2>0:o=1
if o==0:
    if p==0:print(2**n)
    else:print(0)
else:
    print(2**(n-1))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
A - Biscuits
https://atcoder.jp/contests/agc017/tasks/agc017_a

"""
import sys

from math import factorial

def solve(N, P, A):
    even = len([a for a in A if a%2==0])
    odd = len([a for a in A if a%2==1])
    ans = 0
    if P == 0:
        for i in range(0, odd+1, 2):
            ans += 2 ** even * factorial(odd) // factorial(odd - i) // factorial(i)
    else:
        for i in range(1, odd+1, 2):
            ans += 2 ** even * factorial(odd) // factorial(odd - i) // factorial(i)
    return ans


def main(args):
    N, P = map(int, input().split())
    A = [int(a) for a in input().split()]
    ans = solve(N, P, A)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
odd = len([a for a in A if a %2 == 1])
 
if K == 0 and odd == 0:
  print(2**N)
elif K == 1 and odd == 0:
  print(0)
else:
  print(2**(N-1))

Submission status: Accepted

Solution code:
def check(a):
    for i in a:
        if i%2:
            return True
    return False

n,p = map(int, input().split())
a = list(map(int,input().split()))
if check(a):
    print(2**(n-1))
elif p==0:
    print(2**n)
else:
    print(0)

Submission status: Accepted

Solution code:
N,P = map(int,input().split(" "))
A = list(map(lambda x:int(x)%2,input().split(" ")))
f = [1,1]

def frac(x):
    l = len(f)
    if not(l > x) :
        for i in range(x-l+1):
            f.append(f[-1]*(l+i))
    return f[x]

even = A.count(0)
odd = A.count(1)

a = 0
while P <= odd:
    a += frac(odd) // frac(P) // frac(odd-P)
    P += 2
print(a * 2 ** even)

Submission status: Accepted

Solution code:
N, P = map(int, input().split())
As = list(map(int, input().split()))
even = 0
odd = 0
for a in As:
    if a % 2 == 0:
        even += 1
    else:
        odd += 1

E = 2**even
if P == 0:
    O = 1
    o = 1
    for i in range(2, odd+1, 2):
        o = int(o*(odd+1-i)*(odd+2-i)/i/(i-1))
        O += o
else:
    O = odd
    o = odd
    for i in range(3, odd+1, 2):
        o = int(o*(odd+1-i)*(odd+2-i)/i/(i-1))
        O += o
print(E*O)

Submission status: Accepted

Solution code:
N,P=map(int,input().split())
A=list(map(int,input().split()))
A_0=[a%2 for a in A].count(0)
if A_0==N:
    print((2**A_0)*(1-P))
else:
    print(2**(N-1))

Submission status: Accepted

Solution code:
def nCr(n, r):
    ret = 1
    for i in range(1, n+1):
        ret *= i
    for i in range(1, r+1):
        ret //= i
    for i in range(1, n-r+1):
        ret //= i
    return ret

n, p = map(int, input().split())
a = map(int, input().split())
even, odd = 0, 0

for i in a:
  if i & 1:
    odd += 1
  else:
    even += 1

c_even = 2**even
c_odd = 0

start = 1 if p else 0

while start <= odd:
    c_odd += nCr(odd, start)
    start += 2

print(c_even * c_odd)

Submission status: Accepted

Solution code:
n,p=map(int,input().split())
a=[int(i)%2 for i in input().split()]
g=a.count(0)
k=len(a)-g
if (p==1 and k==0):
    ans=0
else:
    ans=(2**g)*(2**k)//(2 if k>0 else 1)
print(ans)

Submission status: Accepted

Solution code:
N, P = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

if all(a % 2 == 0 for a in A):
    print(2 ** N if P == 0 else 0)
else:
    print(2 ** (N - 1))

Submission status: Accepted

Solution code:
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, p = map(int, input().split())
a = [(int(i) % 2) for i in input().split()]
e_num = a.count(0)
o_num = a.count(1)
all_pattern = 2 ** n
o_p = 2 ** (e_num)
o_pattern = o_p
if o_num >= 2:
    for i in range(2, o_num + 1, 2):
        o_pattern += (combinations_count(o_num, i) * o_p)
e_pattern = all_pattern - o_pattern
if p == 1:
    print(e_pattern)
else:
    print(o_pattern)

Submission status: Accepted

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

e = sum(x % 2 == 0 for x in a)
o = sum(x % 2 == 1 for x in a)

if n == 1:
    ans = int(a[0] % 2 == p)
elif p == 1 and o == 0:
    ans = 0
else:
    ans = max((2 ** o) // 2, 1) * 2 ** e

print(ans)

Submission status: Accepted

Solution code:
import math
n,p=map(int,input().split())
A=[int(i) for i in input().split()]
def com(i,j):
  return math.factorial(i)//math.factorial(i-j)//math.factorial(j)
k=0
for a in A:
  if a%2==0:
    k+=1
ans=2**k
mult=0
for i in range((n-k)//2+1):
  mult+=com(n-k,2*i)
ans*=mult
print(ans if p==0 else 2**n-ans)

Submission status: Accepted

Solution code:
n,p = map(int,input().split())
A = [int(i)%2 for i in input().split()]
from collections import Counter
from math import factorial 
D = Counter(A)
one = 0
for i in range(p%2,D[1]+1,2):
    one += factorial(D[1])//(factorial(i)*factorial(D[1]-i))
print((2**D[0])*one)

Submission status: Accepted

Solution code:
n,p = map(int,input().split())
a = list(map(int,input().split()))
m = 0
for i in range(n):
    if a[i]%2 == 1:
        m += 1
if m==0 and p==1:
    print(0)
elif m==0 and p==0:
    print(2**(n))
else:
    print(2**(n-1))

Submission status: Accepted

Solution code:
n, p=map(int, input().split())
a=list(map(int, input().split()))
for i in range(n):
  a[i]%=2
c=a.count(0)
if c==n:
  if p==1:
    print(0)
  else:
    print(2**n)
else:
  print(2**(n-1))

Submission status: Accepted

Solution code:
n,p=map(int,input().split())
arr=list(map(int,input().split()))
dp=[[0]*(n+1) for _ in range(2)]
dp[0][0]=1
for i in range(n):
  if arr[i]%2==0:
    dp[0][i+1]=dp[0][i]*2
    dp[1][i+1]=dp[1][i]*2
  else:
    dp[0][i+1]=dp[0][i]+dp[1][i]
    dp[1][i+1]=dp[0][i]+dp[1][i]
print(dp[p][n])

Submission status: Accepted

Solution code:
N, P = [int(x) for x in input().split()]
As = [int(x) for x in input().split()]

def combination(n, r):
    ans = 1
    for i in range(n, n - r, -1):
        ans *= i
    for i in range(r):
        ans //= (i + 1)
    return ans
n_e = len(list(filter(lambda x: x % 2 == 0, As)))
n_o = N - n_e

ans = 0
for i in range((1 if P == 1 else 0), n_o + 1, 2):
    ans += int(pow(2, n_e)) * combination(n_o, i)

print(ans)

Submission status: Accepted

Solution code:
N, P = map(int, input().split())
A = list(map(int, input().split()))
odd = 0
even = 0
for i in range(N):
  if A[i] %2 == 0:
    even += 1
  else:
    odd += 1
if P == 0:
  if even == N:
    print(2**N)
  else:
    print(2**(N-1))
    
else:
  if even == N:
    print(0)
  else:
    print(2**(N-1))

Submission status: Accepted

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

ODD=0
EVE=0

for i in range(N):
    if A[i]%2==1:
        ODD+=1
    else:
        EVE+=1
        
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**15+7 #出力の制限
N = 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

if P==1:
    O=0
    E=1
    for i in range(EVE):
        E+=cmb(EVE,i,mod)
        E%=(10**15+7)
        
    for i in range((ODD+1)//2):
        O+=cmb(ODD,1+2*i,mod)
        
        
    ans=(E*O)%(10**15+7)
    print(ans)
else:
    O=0
    E=1
    for i in range(EVE):
        E+=cmb(EVE,i,mod)
        E%=(10**15+7)
        
    for i in range((ODD)//2+1):
        O+=cmb(ODD,2*i,mod)
        #print(O)
        
    ans=(E*O)%(10**15+7)
    print(ans)

Submission status: Accepted

Solution code:
n,p=map(int,input().split())
l=list(map(lambda x:int(x)%2,input().split()))
a,b=0,0
for i in l:
  if i>0:
    a+=1
  else:
    b+=1
if a==0:
  if p==0:
    print(2**n)
  else:
    print(0)
else:
  print(2**(n-1))

Submission status: Accepted

Solution code:
N, P = map(int, input().split())
A = [(int(a)) % 2 for a in input().split()]

DP = [[0, 0] for _ in range(N)] #DP[i][0]はi番目で0となる場合の数, DP[i][1]は1となる場合の数
DP[0][A[0]] += 1
DP[0][0] += 1
for i in range(1, N):
    if A[i] == 0:
        DP[i][0] = DP[i-1][0] * 2
        DP[i][1] = DP[i-1][1] * 2
    else:
        DP[i][0] = DP[i-1][1] + DP[i-1][0]
        DP[i][1] = DP[i-1][0] + DP[i-1][1]
print(DP[N-1][P])

Submission status: Accepted

Solution code:
N,P = map(int,input().split())
A = list(map(int,input().split()))
A = [i%2 for i in A]
zero = A.count(0)
one = A.count(1)
ans = 0
def combinations(n, r):
    import math as ma
    return ma.factorial(n)//(ma.factorial(n-r)*ma.factorial(r))

if P == 0:
    ans += 2**zero
    a = 0
    for i in range(one//2):
        a += combinations(one, 2*(i+1))
    ans += a*(2**zero)
else:
    ans += 2**zero
    a = 0
    for i in range(one//2):
        a += combinations(one, 2*(i+1))
    ans += a*(2**zero)
    ans = 2**N - ans
print(ans)

Submission status: Accepted

Solution code:
n, p = map(int, input().split())
a = list(map(int, input().split()))
m = [0, 0]
for i in range(n):
    m[a[i] % 2] += 1
if m[1] == 0 and p == 1:
    print(0)
else:
    print(2**m[0] * 2**(m[1]-1) if m[1] > 0 else 2**m[0])

Submission status: Accepted

Solution code:
n, p = map(int, input().split())
alist = list(map(int, input().split()))

odda = 0
for a in alist:
  if a % 2 == 1:
    odda += 1

if odda == 0:
  if p == 0:
    print(pow(2, n))
  else:
    print(0)
else:
  print(pow(2, n-1))

Submission status: Accepted

Solution code:
n,p=map(int,input().split());a=list(map(int,input().split()));b=[0,0]
for i in a:b[i%2]+=1
if 0==b[1]:print(2**n*((p+1)%2))
else:print(2**(n-1))

Submission status: Accepted

Solution code:
from math import factorial as fact

N, P = map(int, input().split())
A = [int(_) for _ in input().split()]
oddcnt = 0
evencnt = 0
for i in A:
    if i % 2 == 1:
        oddcnt += 1
    else:
        evencnt += 1

even = 2**evencnt
odd = 0
if P == 0:
    for i in range(0, oddcnt+1, 2):
        odd += fact(oddcnt) // (fact(i)*fact(oddcnt-i))
else:
     for i in range(1, oddcnt+1, 2):
        odd += fact(oddcnt) // (fact(i)*fact(oddcnt-i))

print(even*odd)

Submission status: Accepted

Solution code:
n, p = map(int, input().split())
a = list(map(int, input().split()))
odd_count = sum([i % 2 == 1 for i in a])
if p == 0:
    if odd_count == 0:
        print(2**(n-odd_count))
    else:
        print((2**(n-odd_count)) * (2 ** (odd_count - 1)))
else:
    if odd_count == 0:
        print(0)
    else:
        print((2**(n-odd_count)) * (2 ** (odd_count - 1)))

Submission status: Accepted

Solution code:
N, P = map(int, input().split())
lst_A = list(map(int, input().split()))
lst_odd_even = [x%2 for x in lst_A]

if 1 in lst_odd_even:
    ans = 2 ** (N-1)
else:
    if P == 0:
        ans = 2 ** N
    else:
        ans = 0

print(ans)

Submission status: Accepted

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

k = len(list(filter(lambda x: x % 2 == 0, A)))
l = len(list(filter(lambda x: x % 2 == 1, A)))

if k == N:
    print(2 ** N if P == 0 else 0)
else:
    print(2 ** (N - 1))

Submission status: Accepted

Solution code:
n,p=map(int,input().split())
a = list(map(int,input().split()))
k=0
for a_ in a:
    if not a_%2==0:
        k=1
        break
if k:
    print(1<<(n-1))
else:
    print(0) if p==1 else print(1<<n)

Submission status: Accepted

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

ev = 0
ad = 0
for i in A:
  if i % 2 == 0:
    ev += 1
  else:
    ad += 1

if P == 1:
  if ad == 0:
    print("0")
    exit()
  

f = [1, 1]
for i in range(2, ad + 1):
  f.append(f[-1] * i)
num = 0
for i in range(P, ad + 1, 2):
  num += f[ad] // (f[i] * f[ad - i])

print(pow(2, ev) * num)

Submission status: Accepted

Solution code:
import numpy as np 
N, P = map(int, input().split())
A = np.array(list(map(int, input().split())))

even = ((A % 2) == 0).sum()
odd = len(A) - even
flag = True

if (P == 1) & (odd == 0):
  print(0)
  flag = False

if flag:
  if odd == 0:
    print(2**even)
  else:
    print((2**even) * (2**(odd - 1)))

Submission status: Accepted

Solution code:
# coding:utf-8

import sys

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

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 LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, p = LI()
    A = LI()

    even, odd = 0, 0
    for a in A:
        if a % 2:
            odd += 1
        else:
            even += 1

    if odd:
        return 2 ** (n - 1)
    else:
        return 2 ** n if p == 0 else 0


print(main())

Submission status: Accepted

Solution code:
# coding:utf-8

import sys

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

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 LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, p = LI()
    A = LI()

    sum_a = sum(A)
    # dp[i][j]: a_iまでを使ってjを作る組み合わせの総数（iは省略）
    dp = [0] * (sum_a + 1)
    dp[0] = 1
    for i in range(n):
        for j in range(sum_a + 1)[::-1]:
            if j - A[i] < 0:
                break
            if dp[j - A[i]]:
                dp[j] += dp[j - A[i]]

    return sum([dp[i] if i % 2 == p else 0 for i in range(sum_a + 1)])


print(main())

Submission status: Accepted

Solution code:
#AGC023 A: [1]任意の部分和は先頭からの長さの違う2つの部分和の差をとると構成できる[2]かっこいいコードを書くと逆に計算が遅くなることがある
#AGC025 A: 文字列をlist()に入れると1文字ずつ格納できる
#ABC113 B: NumPyの絶対値はnp.abs()


#AGC017 A
'''
問題
i番目の袋にビスケットがAi個入っている
i=1,2,...,N
0個以上の袋をえらび袋の中のビスケットをすべて食べる
食べるビスケットの総数を2で割った余りがPになるような袋の選び方は?
ただしNは1以上50以下

考察
Aiのうち偶数がa個で奇数がN-a個あったとすると
偶数のものは何個えらんでもよい: 2**a通り
奇数のものは2で割った余りがPになるように選べばよい
N-aが奇数のときP=0,1両方に対して2**(N-a-1)通り
N-aが偶数のときもパスカルの三角形を考えるとP=0,1両方に対して2**(N-a-1)通り
よって...
N-a=0のときはP=1なら答えは0
N-a=0のときはP=0なら答えは2**N
N-a>0のときはPによらず答えは2**(N-1)
'''

N,P = map(int,input().split(' '))
odds = [int(x)%2 for x in input().split(' ')].count(1)

if odds > 0:
	print(str(int(2**(N-1))))
elif P == 1:
	print('0')
elif P == 0:
	print(str(int(2**(N))))

Submission status: Accepted

Solution code:
import math
N, P = map(int, input().split())
A = list(map(int, input().split()))
odd = 0
even = 0

def nCr(n, r):
    return math.factorial(n) // math.factorial(n-r) // math.factorial(r)

for a in A:
    if a % 2 == 0:
        even += 1
    else:
        odd += 1
even_cmb = 1
for i in range(1, even+1):
    even_cmb += nCr(even, i)

if P == 0:
    odd_cmb = 1
    for i in range(2, odd+1):
        if i % 2 != 0:
            continue
        odd_cmb += nCr(odd, i)
    ans = even_cmb * odd_cmb
else:
    odd_cmb = 0
    for i in range(1, odd+1):
        if i % 2 == 1:
            odd_cmb += nCr(odd, i)
    ans = even_cmb * odd_cmb
print(ans)
exit()

Submission status: Accepted

Solution code:
N,P = map(int,input().split())
Odd = sum([int(i)%2 for i in input().split()])
Even = N-Odd

def f_C(x,y):
    ans = 1
    for i in range(y):  
        ans *= x-i
    for i in range(y):  
        ans //= i+1
    return(ans)

ans = 2**Even
tmp = 0
for i in range(P,Odd+1,2):
    tmp += f_C(Odd,i)
print(ans*tmp)

Submission status: Accepted

Solution code:
N,P=map(int,input().split())
a=list(map(int,input().split()))
a=list(map(lambda x:x%2,a))
if 1 in a:
    print(2**(N-1))
else:
    if P%2==0:
        print(2**N)
    else:
        print(0)

Submission status: Accepted

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

odd = 0
even = 0
for i in range(N):
    if A[i] % 2 == 1:
        odd += 1
    else:
        even += 1

def nCr(n:int ,r: int) -> int:
    r,v = min(n-r,r),1
    for i in range(r):
        v = (v * (n-i) // (i+1))
    return v

ans = 0
for j in range(1,N+1,2):
    if j > odd:
        break
    ans += nCr(odd,j) * (2**even)

if P == 1:
    print(ans)
else:
    print(2**N - ans)

Submission status: Accepted

Solution code:
from math import factorial


def perm(r, c):
    return factorial(r) // factorial(r - c)


def comb(r, c):
    return perm(r, c) // factorial(c)


N, P = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x % 2, a))
a = list(sorted(a))

cnt_0 = a.count(0)
cnt_1 = a.count(1)

ans = 0
if P == 0:
    for j in range(0, cnt_1 + 1, 2):
        ans += comb(cnt_1, j) * (2 ** cnt_0)
else:
    # P == 1
    for j in range(1, cnt_1 + 1, 2):
        ans += comb(cnt_1, j) * (2 ** cnt_0)
print(ans)

Submission status: Accepted

Solution code:
import math

def cc(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, p = map(int, input().split())
a = list(map(int, input().split()))
o = 0
e = 0
s = 0
for i in a:
  if i%2:
    o += 1
  else:
    e += 1
if p:
  for j in range(1,o+1,2):
    s += cc(o, j)
else:
  for k in range(0,o+1,2):
    s += cc(o, k)
print(s*2**e)

Submission status: Accepted

Solution code:
N, P = map(int,input().split())
A = list(map(int,input().split()))
check = False
for a in A:
  if(a%2 != 0):
    check = True
    break
if(check == True):
  print(2**(N-1))
else:
  if(P == 0):
    print(2**N)
  else:
    print(0)

Submission status: Accepted

Solution code:
import collections
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def combi(a,b):
	num = 1
	for j in range(b):
		num = num*(a-j)//(j+1)
	return num

N,P = IL()
A = IL()

odd = 0
even = 0
for i in A:
	if i%2 != 0:
		odd += 1
	else:
		even += 1

zero = 1
if even != 0:
	for i in range(1,even+1):
		zero += combi(even,i)

if P == 1:
	ans = 0
	for i in range(1,odd+1,2):
		ans += combi(odd,i)*zero
else:
	ans = 0
	for i in range(0,odd+1,2):
		ans += combi(odd,i)*zero

print(ans)

Submission status: Accepted

Solution code:
a, b = map(int,input().split())
X = list(map(int, input().split()))
odd = 0
even = 0
for i in X:
    if(i % 2 == 1):
        odd += 1
    else:
        even += 1

if(odd!=0):
    odd-=1
ans = (2**even) * (2**(odd))

if(b==0):
    print(ans)
else:
    print(2**a - ans)