Submission #1891254

Source Code Expand

Copy
```import itertools
import collections
import math
N,A=map(int,raw_input().split())
#print N,A
x=collections.Counter(map(int,raw_input().split()))
#print x

iv=[i for i in x.keys()]	#Item value
ic=[]	#Item count
for i in x.items():
tmp=[i for i in range(i[1]+1)]
ic.append(tmp)

ic_n=[len(_)-1 for _ in ic]

p=list(itertools.product(*ic))
#print "# p"
#print p		#Pattern

a=[]
for m in p:
t_sum=0
for j,k in zip(m,iv):
t_sum+=j*k
#print t_sum,len(m)
if sum(m)!=0 and t_sum/sum(m)==A and t_sum%sum(m)==0 and sum(m)!=0:
#print m,iv,t_sum,sum(m)
a.append(m)

#print "# a"
#print a

def combination(n,r):
g=[math.factorial(i) for i in range(100) ]
return int(g[n]/(g[r]*g[n-r]))

ans=0
for i in a:
t_cnt=1
for j,k in zip(i,ic_n):
if j!=0 or j!=k:
t_cnt*= combination(k,j)
pass
#print t_cnt
ans+=t_cnt
print ans
```

#### Submission Info

Submission Time 2017-12-21 19:23:41+0900 C - 高橋君とカード / Tak and Cards KUMAWO Python2 (2.7.6) 0 879 Byte TLE

#### Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 example_01.txt, example_02.txt, example_03.txt, example_04.txt
Case Name Status Exec Time Memory
example_01.txt 17 ms 2936 KB
example_02.txt 11 ms 2812 KB
example_03.txt 36 ms 2812 KB
example_04.txt 19 ms 2812 KB