Submission #855506


Source Code Expand

Copy
N, A = gets.split(/ /).collect{|i| i.to_i}


exit if N > 16

list_s = []
count_j = 0
list_l = []

gets.split(/ /).collect{|x|
	x = x.to_i
	if x == A
		count_j += 1
	elsif x < A
		list_s << (A - x)
	elsif
		list_l << (x - A)
	end
}

def make_patterns(list, i, pattern, results)
	if i == list.length
		if pattern.length > 0
			sum = pattern.inject(:+)
		else
			sum = 0
		end
		if results[sum]
			results[sum] += 1
		else
			results[sum] = 1
		end
	else
		make_patterns(list, i + 1, pattern, results)
		make_patterns(list, i + 1, pattern + [list[i]], results)
	end
end

results_s = {}
make_patterns(list_s, 0, [], results_s)

results_l = {}
make_patterns(list_l, 0, [], results_l)

pattern_count_j = 2 ** count_j
count = pattern_count_j - 1
results_s.each{|sum_s, count_s|
	if sum_s > 0 && count_l = results_l[sum_s]
		count += count_s * count_l * pattern_count_j
	end
}

p count


Submission Info

Submission Time
Task C - Tak and Cards
User TakaakiUmedu
Language Ruby (2.3.3)
Score 200
Code Size 935 Byte
Status WA
Exec Time 168 ms
Memory 1916 KB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 200 / 200 0 / 100
Status
AC × 3
WA × 1
AC × 12
AC × 12
WA × 12
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 17 ms 1788 KB
example_02.txt AC 16 ms 1788 KB
example_03.txt AC 16 ms 1788 KB
example_04.txt WA 17 ms 1788 KB
subtask1_01.txt AC 17 ms 1788 KB
subtask1_02.txt AC 17 ms 1788 KB
subtask1_03.txt AC 168 ms 1916 KB
subtask1_04.txt AC 166 ms 1916 KB
subtask1_05.txt AC 18 ms 1788 KB
subtask1_06.txt AC 16 ms 1788 KB
subtask1_07.txt AC 16 ms 1788 KB
subtask1_08.txt AC 20 ms 1788 KB
subtask1_09.txt AC 35 ms 1916 KB
subtask2_01.txt WA 16 ms 1788 KB
subtask2_02.txt WA 16 ms 1788 KB
subtask2_03.txt WA 16 ms 1788 KB
subtask2_04.txt WA 16 ms 1788 KB
subtask2_05.txt WA 17 ms 1788 KB
subtask2_06.txt WA 17 ms 1788 KB
subtask2_07.txt WA 16 ms 1788 KB
subtask2_08.txt WA 16 ms 1788 KB
subtask2_09.txt WA 16 ms 1788 KB
subtask2_10.txt WA 16 ms 1788 KB
subtask2_11.txt WA 16 ms 1788 KB