Submission #856386


Source Code Expand

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


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)
	results = {0 => 1}
	
	list.each{|x|
		new_results = {}
		results.each{|sum, count|
			if new_results[sum]
				new_results[sum] += count
			else
				new_results[sum] = count
			end
			
			new_sum = sum + x
			if new_results[new_sum]
				new_results[new_sum] += count
			else
				new_results[new_sum] = count
			end
		}
		results = new_results
	}
	
	results
end

results_s = make_patterns(list_s)
results_l = make_patterns(list_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 300
Code Size 928 Byte
Status AC
Exec Time 30 ms
Memory 2812 KB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 200 / 200 100 / 100
Status
AC × 4
AC × 12
AC × 24
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 18 ms 1788 KB
example_03.txt AC 17 ms 1788 KB
example_04.txt AC 18 ms 1788 KB
subtask1_01.txt AC 17 ms 1788 KB
subtask1_02.txt AC 17 ms 1788 KB
subtask1_03.txt AC 17 ms 1788 KB
subtask1_04.txt AC 17 ms 1788 KB
subtask1_05.txt AC 17 ms 1788 KB
subtask1_06.txt AC 17 ms 1788 KB
subtask1_07.txt AC 17 ms 1788 KB
subtask1_08.txt AC 17 ms 1788 KB
subtask1_09.txt AC 18 ms 1916 KB
subtask2_01.txt AC 24 ms 2300 KB
subtask2_02.txt AC 30 ms 2812 KB
subtask2_03.txt AC 23 ms 2172 KB
subtask2_04.txt AC 17 ms 1788 KB
subtask2_05.txt AC 18 ms 1916 KB
subtask2_06.txt AC 18 ms 1916 KB
subtask2_07.txt AC 17 ms 1788 KB
subtask2_08.txt AC 24 ms 2428 KB
subtask2_09.txt AC 26 ms 2428 KB
subtask2_10.txt AC 29 ms 2684 KB
subtask2_11.txt AC 22 ms 2172 KB