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())
a = list(map(int, input().split()))
a_even = 0
a_odd = 0
for i in a:
    if i % 2 == 0:
        a_even += 1
    else:
        a_odd += 1
        
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

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

    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

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k]) 
    
    return result
        
if p == 0:
    odd = 0
    for i in range(a_odd//2 + 1):
        odd += cmb(a_odd, 2 * i)
    print((2 ** (a_even)) * odd)
else:
    odd = 0
    if a_odd % 2 == 0:
        for i in range(a_odd//2):
            odd += cmb(a_odd, 2 * i + 1)
    else:
        for i in range(a_odd//2 + 1):
            odd += cmb(a_odd, 2 * i + 1)
    print((2 ** (a_even)) * odd)

Submission status: Accepted

Solution code:
N = 52  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)

for i in range(2, N + 1):
    fact.append(fact[-1] * i)

def cmb(n, r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return (fact[n] // fact[r]) // fact[n-r] 

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

cnt = [0,0]
for i in range(N):
    cnt[A[i]%2] += 1

ans = 2**(cnt[0])
mm = 0
if P==0:
    for i in range(0,cnt[1]+1,2):
        mm += cmb(cnt[1],i)
else:
    for i in range(1,cnt[1]+1,2):
        mm += cmb(cnt[1],i)

print(ans*mm)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n, p = map(int, input().split())
a = list(map(int, input().split()))
def combi(x, y):
    if y == 0:
        return 1
    if x == 0:
        return 0
    return math.factorial(x) / (math.factorial(x - y) * math.factorial(y))
odd_count = 0
even_count = 0
for i in range(n):
    if a[i] % 2 == 0:
        even_count += 1
    else:
        odd_count += 1
ans = 0
if p % 2 == 0:
    ans += pow(2,even_count)
    tmp = 0
    for i in range(0,odd_count+1,2):
        tmp += combi(odd_count,i)
    ans *= tmp
else:
    ans += pow(2,even_count)
    tmp = 0
    for i in range(1,odd_count+1,2):
        tmp += combi(odd_count,i)
    ans *= tmp
print(int(ans))

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
# sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = True
show_flg = False


def main():
    N, P = MI()
    A = LI()
    total = sum(A)
    dp = [0] * (total+1)
    dp[0] = 1

    # tmp = [0] * (total+1)
    # for i in range(2 ** N):
    #     groups = []
    #     for j in range(N):
    #         if ((i >> j) & 1):
    #             groups.append(A[j])
    #     tmp[sum(groups)] += 1

    # print(tmp)

    for i in range(N):
        dp_next = [0] * (total+1)
        for j in range(total+1):
            if dp[j] >= 1:
                dp_next[j] = max(dp[j], dp_next[j])
                if j + A[i] <= total:
                    dp_next[j+A[i]] = dp[j+A[i]]
                    dp_next[j+A[i]] += dp[j]
                # print(i, j, dp_next, dp[j])
        # print(i, dp_next)
        dp = dp_next

    ans = 0
    for i in range(total+1):
        if i % 2 == P:
            ans += dp[i]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import factorial
def c(n,k):
  return factorial(n)//factorial(k)//factorial(n-k)
n,p=map(int,input().split())
a=list(map(int,input().split()))
odd=0
for i in a:
  if i%2==1:
    odd+=1
even = n-odd
m = (odd // 2) + 1
even_ = pow(2,even)
odd_ = 0
for i in range(m):
  odd_ += c(odd,i*2)
if p==0:
  print(even_ * odd_)
else:
  print(pow(2,n)-even_ * odd_)

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce
def sml_cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def main():
    n, p = map(int, input().split())
    a = list(map(int, input().split()))
    cnt_ev = 0
    cnt_od = 0
    for v in a:
        if v % 2 == 0:
            cnt_ev += 1
        else:
            cnt_od += 1
    if p == 0:
        x, y = 0, 0
        for i in range(cnt_ev+1):
            x += sml_cmb(cnt_ev, i)
        for i in range(0, cnt_od+1, 2):
            y += sml_cmb(cnt_od, i)
        print(x*y)
    else:
        x, y = 0, 0
        for i in range(cnt_ev+1):
            x += sml_cmb(cnt_ev, i)
        for i in range(1, cnt_od+1, 2):
            y += sml_cmb(cnt_od, i)
        print(x*y)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,p = map(int,input().split())
a = list(map(int,input().split()))
odd = [i for i in a if i%2==1]
eve = [i for i in a if i%2==0]
odd_len = len(odd)
eve_len = len(eve)
if p==0:
    ans = 2**eve_len
else:
    ans = 0
count = 0
if p==0:
    if odd_len!=0:
        ans *= 2**odd_len//2
else:
    ans +=   (2**eve_len)*(2**odd_len//2)
print(ans)

Submission status: Accepted

Solution code:
N,P=map(int,input().split())
A=list(map(int,input().split()))
a=0
for i in A:
  if i%2==0:
    a+=1
b=N-a
c=0
import math
def comb(n,r):
  return math.factorial(n) // (math.factorial(n-r)*math.factorial(r))  
for i in range(b//2+1):
  c+=comb(b,2*i)
if P==0:
  print((2**a)*c)
else:
  print(2**N-(2**a)*c)

Submission status: Accepted

Solution code:
def main():
  n, p = input_list()
  a = list(input_list())
  # 全て偶数かどうか
  is_even = True
  for v in a:
    if v % 2 != 0:
      is_even = False
      break
  if is_even:
    if p == 0:
      print(2**n)
      exit()
    else:
      print(0)
      exit()
  else:
    print(2**(n-1))
  
  exit()
  if p == 0:
    # 偶数の場合：
    for i in range(n):
      if i % 2 == 0:
        r += combinations_count(n, i)
    if r % 2 != 0:
      r += 1
  else:
    # 奇数の場合：奇数を奇数個かける
    for i in range(n):
      if i % 2 != 0:
        r += combinations_count(n, i)
    if r > 0:
      r += 1
  print(r)  
  exit()
  for i in range(bi+1):
    fi = format(i, '0'+str(n)+'b')
    ans = 0
    for index, v in enumerate(fi):
      if v == '1':
        ans += a[index]
    if ans % 2 == p:
      r += 1
  print(r)
  
def input_list():
  return map(int, input().split())

def input_list():
  return map(int, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

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

import math
import fractions

from functools import reduce
main()

Submission status: Accepted

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

odd = 0
even = 0

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

if odd == 0:
    if P == 1:
        ans = 0
    else:
        ans = (2 ** even) 
else:
    ans = (2 ** even) * ((2 ** odd) // 2)

print(ans)

Submission status: Accepted

Solution code:
n, p = map(int, input().split())
a = list(map(int, input().split()))
flag = True
for i in a:
    if i % 2 == 0:
        continue
    else:
        flag = False
        break

if n == 1 and a[0] % 2 == 0:
    if p == 0:
        print(2)
    else:
        print(0)
elif n == 1 and a[0] % 2 == 1:
    print(1)

else:
    if flag:
        if p == 0:
            print(2 ** n)
        else:
            print(0)
    else:
        print(2 ** n // 2)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
lst = list(map(int,input().split()))
e,o = 0,0
for i in range(n):
    if lst[i]%2==0:
        e += 1
    else:
        o += 1

if o==0:
    if k==0:
        print(2**n)
    else:
        print(0)
else:
    print(2**(n-1))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def main():
    N, P = map(int, input().split())
    A = list(map(int, input().split()))

    pre = [1, 0]

    for i, a in enumerate(A):
        if a&1:# 奇数
            tmp = [sum(pre), sum(pre)]
        else:# 偶数
            tmp = [pre[0] * 2, pre[1] * 2]
        pre = tmp
    
    print(pre[P])

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from math import factorial
def f(a, b):
    if a == 0 or b == 0:
        return 1
    else:
        return factorial(a) // (factorial(a - b) * factorial(b))
n, p = map(int, input().split())
a = [int(x) % 2 for x in input().split()]
e, o = a.count(0), a.count(1)
if p == 0:
    print((2**e)*sum([f(o, i) for i in range(0, o+1, 2)]))
else:
    print((2**e)*sum([f(o, i) for i in range(1, o+1, 2)]))

Submission status: Accepted

Solution code:
n,p = map(int, input().split())
a = list(map(int, input().split( )))
a = [a[i]%2 for i in range(n)]
dp0 = 1
dp1 = 0

for i in range(n):
    if a[i]%2:
        dp_0 = dp1 + dp0
        dp_1 = dp1 + dp0
    
        dp0,dp1 = dp_0,dp_1
    else:
        dp0*=2
        dp1*=2

if p:
    print(dp1)
else:
    print(dp0)

Submission status: Accepted

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

if sum(A) == 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()))
A = [a%2 for a in A]
if sum(A) == 0:
    print(pow(2, n) if p==0 else 0)
elif n>=2:
    print(pow(2, n)//2)
else:
    print(1 if A[0]==p else 0)

Submission status: Accepted

Solution code:
def cmb(n,r):
    if n==0 or r==0:
        return 1
    else:
        ans=1
        for i in range(1,min(r,n-r)+1):
            ans=ans*(n-i+1)//i
        return ans

n,p=map(int,input().split())
a=list(map(int,input().split()))
buf=0
for i in range(n):
    if a[i]%2==1:
        buf+=1
ans=0
if p==0:
    for i in range(buf//2+1):
        ans+=cmb(buf,2*i)
    ans*=2**(n-buf)
    print(ans)
else:
    for i in range((buf+1)//2):
        ans+=cmb(buf,2*i+1)
    ans*=2**(n-buf)
    print(ans)

Submission status: Accepted

Solution code:
N, P = map(int, input().split())
A = list(map(int, input().split()))
# print(N, P, A)
num_odd = 0
num_even = 0
for a in A:
    if a % 2 == 0:
        num_even += 1
    else:
        num_odd += 1
# print(num_odd, num_even)

def cmb(n, r):
    ans = 1
    for i in range(r):
        ans *= n
        n -= 1
    ans1 = 1
    for i in range(1, r + 1):
        ans1 *= i
    return ans // ans1

ans = 0

if P == 0:
    select_odd = 0
    for i in range(0, num_odd + 1, 2):
        select_odd += cmb(num_odd, i)
    for i in range(0, num_even + 1):
        ans += cmb(num_even, i) * select_odd
else:
    select_odd = 0
    for i in range(1, num_odd + 1, 2):
        select_odd += cmb(num_odd, i)
    for i in range(0, num_even + 1):
        ans += cmb(num_even, i) * select_odd
print(ans)

Submission status: Accepted

Solution code:
N,P,*A=map(int, open(0).read().split())
o=sum(a&1 for a in A)
e=N-o

ans = 0
for i in range(1,o+1,2):
    res = 1
    for r in range(i):
        res *= o-r
        res //=r+1
    ans += res
ans*=2**e
if not P:
    ans=2**N-ans
print(ans)

Submission status: Accepted

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

odd = []
even = []
ans = 0
for i in A:
  if (i % 2 == 1):
    odd.append(i)
  else:
    even.append(i)

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  
if (P == 0):
  l_odd = len(odd)
  num = 0
  while l_odd >= num:
    ans += combinations_count(l_odd, num)
    num += 2
  if (len(even)!=0):
    ans *= 2**len(even)
else:
  l_odd = len(odd)
  num = 1
  while l_odd >= num:
    ans += combinations_count(l_odd, num)
    num += 2
  if (len(odd)!=0):
    ans *= 2**len(even)
print(ans)

Submission status: Accepted

Solution code:
import math,itertools

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

def main():
    N,P = map(int,input().split())
    A = list(map(int,input().split()))
    odd_A = [A[i] for i in range(N) if A[i]%2 != 0]
    even_A = [A[i] for i in range(N) if A[i]%2 == 0]
    allpat = 2**N
    comb = 0
    for i in range(0,len(odd_A)+1,2):
        comb += combinations_count(len(odd_A),i)
    evenpat = (2**len(even_A))*comb
    oddpat = allpat - evenpat
    ans = oddpat if P == 1 else evenpat
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

if p==0:
    ans=2**n
else:ans=0
    
for i in range(n):
    if a[i]%2!=0:
        ans=2**(n-1)
        break
print(ans)

Submission status: Accepted

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

odd = sum([item % 2 for item in a])
even = n - odd

ans = 0
if even == n:
    if p == 1:
        print(0)
    else:
        print(2 ** n)
elif n == 1 and odd == 1 and p == 0:
    print(0)
else:
    # 偶数枚入った袋は選ぶor選ばない自由
    ans += 2 ** even
    # 奇数枚入った袋は2で割って余りがPになるよう選ぶ個数を決める
    ans *= 2 ** (odd - 1)
    print(ans)

Submission status: Accepted

Solution code:
n, p = map(int, input().split())
a = [_ % 2 for _ in [int(_) for _ in input().split()]]
num_zero = 0
num_one = 0
for _ in a:
    if _ == 0:
        num_zero += 1
    else:
        num_one += 1
#print(num_zero, num_one)

ans = 0
if p == 0:
    if num_one == 0:
        ans = 2 ** n
    else:
        ans = 2 ** (n - 1)
else:
    if num_one == 0:
        ans = 0
    else:
        ans = 2 ** (n - 1)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32

MOD = 2  # type: int

def solve(N: int, P: int, A: "List[int]"):

    if all([i%2 == 0 for i in A]):
        if P == 0:
            print(2**N)
        else:
            print(0)

    else:
        od = len([i%2 == 1 for i in A])
        print(2**(N-1))

    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
    P = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, P, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce


n,p = map(int,input().split())
L = list(map(int,input().split()))

LLeven = map(lambda x: x % 2, L)
LLodd = map(lambda x: x % 2, L)

even = list(LLeven).count(0)
odd = list(LLodd).count(1)

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


def pattern(x):
    (choose_even,choose_odd) = (0,0)
    for i in range(x+1):
        if i%2 == 0:
            choose_even += cmb(x,i)
        else:
            choose_odd += cmb(x,i)
    return(choose_even,choose_odd)

if p == 0:
    print(2**even * pattern(odd)[0])
else:
    print(2**even * pattern(odd)[1])

Submission status: Accepted

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

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

Submission status: Accepted

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

odd = [a%2 for a in A].count(1)
even = N-odd

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

Submission status: Accepted

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

odd = [a%2 for a in A].count(1)
even = N - odd
if odd == 0:
    print(0 if P else 2**N)
else:
    print(2**(N-1))

Submission status: Accepted

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

odd = [a % 2 == 1 for a in A].count(True)
even = N - odd

C = [[0] * 51 for i in range(51)]
C[0][0] = 1
for i in range(1, 51):
    C[i][0] = 1
    for j in range(1, i + 1):
        C[i][j] = C[i - 1][j - 1] + C[i - 1][j]

if P == 1 and odd == 0:
    print(0)
else:
    x = 2 ** even
    y = 0
    i = P
    while i <= odd:
        y += C[odd][i]
        i += 2
    print(x * y)

Submission status: Accepted

Solution code:
n, p, *a = map(int, open(0).read().split())
even = odd = 0
for i in a:
    if i%2: odd += 1
    else: even += 1
ecr = [1] * (even+1)
for i in range(1, even): ecr[i] = ecr[i-1]*(even-i+1)//i
ocr = [1] * (odd+1)
for i in range(1, odd): ocr[i] = ocr[i-1]*(odd-i+1)//i
print(sum(ecr) * sum(ocr[p::2]))

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(0,N):
    if A[i]%2==1:
        odd=odd+1
    else:
        even=even+1
if odd==0:
    if P==0:
        print(2**(even))
    else:
        print(0)
else:
    print((2**(odd-1))*(2**(even)))

Submission status: Accepted

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

dp = [[None for remainder in range(2)] for i in range(N + 1)]
dp[0][0] = 1
dp[0][1] = 0

for i in range(N):
    for r in range(2):
        dp[i + 1][r] = dp[i][r] + dp[i][(r + A[i]) % 2]

print(dp[N][P])

Submission status: Accepted

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

flag = True
for a in A:
    if a % 2 != 0:
        flag = False

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

print(ans)

Submission status: Accepted

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

for a in al:
    if a % 2 == 1:
        print(2**(n-1))
        exit()

if p == 0:
    print(2**n)
else:
    print(0)

Submission status: Accepted

Solution code:
from sys import stdin

n,p = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))

if all(i%2 == 0 for i in li):
    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=list(map(int,input().split(' ')))
for i in A:
    if i%2 != 0:
        print(2**(N-1))
        exit()
if P ==0:
    print(2**N)
else:
    print(0)

Submission status: Accepted

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

even_num=0
odd_num=0

for a in A:
    if a%2==0:
        even_num+=1
    else:
        odd_num+=1

ev_case = 2**even_num


from math import factorial

res=0
for i in range(P,odd_num+1,2):                                                                   res += factorial(odd_num) / factorial(i) / factorial(odd_num - i)

print(int(ev_case*res))

Submission status: Accepted

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

flg = True
for a in alist:
    if a % 2 != 0:
        flg = False
        break
if flg:
    if P == 0:
        print(2**N)
    else:
        print(0)
else:
    print(2**(N - 1))

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil, floor
from collections import defaultdict
import itertools
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

N, M, = map(int, input().split())
L = [int(v) % 2 for v in input().split()]
L.sort()

zc = len([v for v in L if v == 0])
oc = len([v for v in L if v == 1])

if oc == 0:
    if M == 0:
        print(2 ** N)
    else:
        print(0)
else:
    print(2 **  (N - 1))

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)

if one == 0 and P == 1:
    print(0)
else:
    print( (2**zero) * (2**(max(0, one-1))) )

Submission status: Accepted

Solution code:
DP = [[0 for _ in range(2)] for _ in range(55)]
DP[0][0] = 1
N, P, *A = map(int, open(0).read().split())
for i in range(N):
  DP[i+1][0] += DP[i][0]
  DP[i+1][0] += DP[i][A[i]%2]
  DP[i+1][1] += DP[i][1]
  DP[i+1][1] += DP[i][(A[i]%2)^1]
print(DP[N][P])

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 = list(map(int,input().split()))
odd_num = 0
even_num = 0
for a in A:
    if a % 2 == 1:
        odd_num += 1
    else:
        even_num += 1
ans = 0

if P == 1:
    if odd_num == 0:
        ans = 0
    else:
        for i in range(1, N + 1, 2):
            ans += combinations_count(N, i)
else:
    if odd_num == 0:
        ans = 2 ** even_num
    else:
        for i in range(0, N + 1, 2):
            ans += combinations_count(N, i)
print(ans)

Submission status: Accepted

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

jug = True
for i in range(n):
    if a[i] % 2 == 1:
        jug = False
        break

if jug:
    if p == 0:
        print(2 ** n)
    else:
        print(0)
else:
    print(2 ** (n - 1))

Submission status: Accepted

Solution code:
# P=0 -> 奇数を偶数個といくつかの偶数個
# P=1 -> 奇数を奇数個といくつかの奇数個
# 1000回くらいWAしたのでどんどんアドホックになっていった

n, p = map(int, input().split())
odds = n - len(list(filter(lambda x: int(x) % 2 == 0, input().split())))
evens = n - odds


def ncr(n, r):
    res = 1
    for i in range(1, r + 1):
        res = res * (n - i + 1) // i
    return res


ans = 0
if p == 0:
    for i in range(0, odds + 1, 2):
        ans += ncr(odds, i)
    if evens > 0:
        ans *= max(1, 2 ** evens)
else:
    if odds > 0:
        for i in range(1, odds + 1, 2):
            ans += ncr(odds, i)
        ans *= max(1, 2 ** evens)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
#from itertools import permutations


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



def main():
    #N = int(input())
    N,P = map(int, input().split())
    #vP = tuple(map(int, input().split()))
    vA = list(map(int, input().split()))
    #vA = list(range(1,N+1))
    
    dp = [1, 0]
    print(dp, file=sys.stderr)
    for i,c in enumerate(vA,1):
        a = c%2
        p0, p1 = dp[a], dp[1^a]
        dp[0] += p0
        dp[1] += p1
    print(dp, file=sys.stderr)
    print(dp[P])
    #S = input().rstrip()
    #print(S)
    #print(lcm(N, M))
    #print("Yes" if X<=500*K else "No")
    #print(S.count("ABC"))
    #print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

dp = [[0 for _ in range(2)] for _ in range(N+1)]
dp[0][0] = 1

for i in range(1,N+1):
	if A[i-1]%2 == 0:
		dp[i][0] = 2*dp[i-1][0]
		dp[i][1] = 2*dp[i-1][1]
	else:
		dp[i][0] = dp[i-1][0] + dp[i-1][1]
		dp[i][1] = dp[i-1][0] + dp[i-1][1]

print(dp[N][P])

Submission status: Accepted

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

odd = 0
even = 0

for i in range(n):
    if ls[i] % 2 == 0:
        even += 1
    elif ls[i] % 2 == 1:
        odd += 1

if p == 0:
    print((2 ** even) * max(2 ** (odd - 1), 1))
elif p == 1:
    if odd == 0:
        print(0)
    else:
        print((2 ** even) * max((2 ** (odd - 1), 1)))

Submission status: Accepted

Solution code:
#coding: utf-8
"""
- Aは奇数か偶数かだけ分かれば良い
- Pが0でも1でも計算内容はそんなに変わらない
奇数がk個のとき、P=1の解はどうなるか
1 1C1
2 2C1
3 3C1+3C3
4 4C1+4C3
5 5C1+5C3+5C5
にそれぞれ2^(偶数の数)
"""
from math import factorial
def comb(n, r):
    return factorial(n) // factorial(r) // factorial(n - r)
n, p = map(int, input().split())
A = list(map(int, input().split()))
even = 0
odd = 0
for a in A:
    if a%2==0:
        even+=1
    else:
        odd+=1
ans = 0
for k in range(1,odd+1,2):
    ans += comb(odd,k)
ans *= 2**even
if p==0:
    print (2**n-ans)
else:
    print (ans)

Submission status: Accepted

Solution code:
N, P = map(int, input().split())
O = sum([int(a) % 2 for a in input().split()])
E = N - O
fa = [1]
for i in range(1, 51):
    fa.append(fa[-1] * i)
ans = 0
for i in range(P, O+1, 2):
    ans += fa[O] // (fa[i] * fa[O-i])

print(ans * 2**E)

Submission status: Accepted

Solution code:
def fact(x):
    if x == 0 or x == 1:
        return 1

    ans = 1
    for i in range(1,x+1):
        ans *= i
    return ans
def combi(n,r):
    return fact(n)//((fact(r))*(fact(n-r)))

N, P = map(int,input().split())
A = list(map(lambda x: int(x)%2,input().split()))
cnt1 = A.count(1)
t = P
sumC = 0
while  t <= cnt1:
    sumC += combi(cnt1,t)
    t += 2
print(sumC*(2**(N-cnt1)))

Submission status: Accepted

Solution code:
N,P=map(int,input().split())
A = list(map(int,input().split()))
x = sum([1 for i in A if i%2==0])
y = N - x
#even
ans = (2**x) * (2**max(0,y-1))
#odd
if P == 1:
  ans = (2**x)*(2**y)-ans
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools
from math import factorial
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n, p = LI()
    a = LI()
    odd = sum(map(lambda x: x & 1, a))
    even = sum(map(lambda x: (x ^ 1) & 1, a))
    t0 = 0
    t1 = 0
    for i in range(0, odd + 1, 2):
        a = factorial(odd)
        b = factorial(i)
        c = factorial(odd - i)
        t0 += a // b // c
    for i in range(1, odd + 1, 2):
        a = factorial(odd)
        b = factorial(i)
        c = factorial(odd - i)
        t1 += a // b // c
    print(2 ** even * t1 if p else 2 ** even * t0)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,p=map(int,input().split())
a=list(map(int,input().split()))
even=len([a[i] for i in range(len(a)) if a[i]%2==0])
odd=len([a[i] for i in range(len(a)) if a[i]%2!=0])

def make_c(n):
	nck=[1]
	child=n
	mother=1
	for i in range(1,n+1):
		nck.append(nck[i-1]*child//mother)
		child-=1
		mother+=1
	return nck
	


if(p==0):
	comb=make_c(odd)
	comb=comb[0::2]
	odd_comb=sum(comb)	
	ans=(2**even)*odd_comb
else:
	comb=make_c(odd)
	comb=comb[1::2]
	odd_comb=sum(comb)
	ans=(2**even)*odd_comb	
print(ans)