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
Task C - 高橋君とカード / Tak and Cards
User KUMAWO
Language Python2 (2.7.6)
Score 0
Code Size 879 Byte
Status

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 example_01.txt, example_02.txt, example_03.txt, example_04.txt
Subtask1 0 / 200 example_01.txt, example_02.txt, example_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt
All 0 / 100 example_01.txt, example_02.txt, example_03.txt, example_04.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.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
subtask1_01.txt
subtask1_02.txt 15 ms 2812 KB
subtask1_03.txt 11 ms 2812 KB
subtask1_04.txt 11 ms 2812 KB
subtask1_05.txt 15 ms 2812 KB
subtask1_06.txt 11 ms 2812 KB
subtask1_07.txt 11 ms 2812 KB
subtask1_08.txt 442 ms 4728 KB
subtask1_09.txt 129 ms 8872 KB
subtask2_01.txt
subtask2_02.txt
subtask2_03.txt
subtask2_04.txt 27 ms 2936 KB
subtask2_05.txt 12 ms 2812 KB
subtask2_06.txt 12 ms 2812 KB
subtask2_07.txt 12 ms 2812 KB
subtask2_08.txt
subtask2_09.txt
subtask2_10.txt
subtask2_11.txt