Submission #855848


Source Code Expand

Copy
from collections import defaultdict
def enum(n,x,A):
	D = defaultdict(int)
	D[0] = 1
	L = [None]*(1<<n)
	L[0] = 0
	for k in xrange(1<<n):
		for j in xrange(n):
			jbit = 1<<j
			if (k&jbit): continue
			nbit = k + jbit
			if L[nbit] is None: 
				nv = L[k] + x[j]
				L[nbit] = nv
				cnt = bin(nbit).count("1")
				D[nv-A*cnt] += 1
	return D
def solve():
	N,A = map(int,raw_input().split())
	x = map(int,raw_input().split())
	n1 = N/2; n2 = N - n1
	D1 = enum(n1,x[:n1],A)
	D2 = enum(n2,x[n1:],A)
	ans = 0
	for k,v in D1.iteritems():
		ans += D2[-k]*v
	print ans - 1
solve()

Submission Info

Submission Time
Task C - Tak and Cards
User taktah
Language PyPy2 (5.6.0)
Score 200
Code Size 601 Byte
Status TLE
Exec Time 2148 ms
Memory 462620 KB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 200 / 200 0 / 100
Status
AC × 4
AC × 12
AC × 15
TLE × 9
Set Name Test Cases
Sample example_01.txt, example_02.txt, example_03.txt, example_04.txt
Subtask1 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 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 AC 58 ms 9072 KB
example_02.txt AC 57 ms 8944 KB
example_03.txt AC 61 ms 8944 KB
example_04.txt AC 442 ms 23836 KB
subtask1_01.txt AC 82 ms 9840 KB
subtask1_02.txt AC 75 ms 9840 KB
subtask1_03.txt AC 76 ms 9840 KB
subtask1_04.txt AC 76 ms 9840 KB
subtask1_05.txt AC 76 ms 9840 KB
subtask1_06.txt AC 57 ms 8944 KB
subtask1_07.txt AC 57 ms 8944 KB
subtask1_08.txt AC 76 ms 9968 KB
subtask1_09.txt AC 75 ms 9968 KB
subtask2_01.txt TLE 2143 ms 441756 KB
subtask2_02.txt TLE 2141 ms 425116 KB
subtask2_03.txt TLE 2133 ms 291356 KB
subtask2_04.txt TLE 2143 ms 442652 KB
subtask2_05.txt TLE 2141 ms 422044 KB
subtask2_06.txt TLE 2145 ms 425884 KB
subtask2_07.txt TLE 2148 ms 462620 KB
subtask2_08.txt AC 357 ms 21020 KB
subtask2_09.txt AC 364 ms 21148 KB
subtask2_10.txt TLE 2108 ms 64284 KB
subtask2_11.txt TLE 2108 ms 60700 KB