Last active
July 10, 2017 14:54
-
-
Save whatalnk/cd78b7e0cb36c534642f997dc2fd31fa to your computer and use it in GitHub Desktop.
AtCoder AGC #017
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Submitted answer, AC | |
n, p_ = gets.chomp.split(" ").map(&:to_i) | |
a = gets.chomp.split(" ").map(&:to_i) | |
ne = 0 | |
no = 0 | |
a.each do |i| | |
if i.even? then | |
ne += 1 | |
else | |
no += 1 | |
end | |
end | |
@fac = Array.new(n) | |
def fact(n) | |
@fac[0] = 1 | |
(1..n).each do |i| | |
@fac[i] = @fac[i-1] * i | |
end | |
end | |
fact(50) | |
def comb(n, k) | |
return 1 if k == 0 | |
return @fac[n] / (@fac[n-k] * @fac[k]) | |
end | |
ans = 0 | |
if p_ == 0 then | |
anse = (0..ne).map{|k| comb(ne, k)}.inject(:+) | |
anso = 0 | |
0.step(no, 2){|k| anso += comb(no, k)} | |
ans = anse * anso | |
else | |
anse = (0..ne).map{|k| comb(ne, k)}.inject(:+) | |
anso = 0 | |
1.step(no, 2){|k| anso += comb(no, k)} | |
ans = anse * anso | |
end | |
puts ans |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n, p_ = gets.chomp.split(" ").map(&:to_i) | |
a = gets.chomp.split(" ").map(&:to_i) | |
ne = 0 | |
no = 0 | |
a.each do |i| | |
if i.even? then | |
ne += 1 | |
else | |
no += 1 | |
end | |
end | |
if no == 0 then | |
if p_ == 0 | |
puts 2 ** n | |
else | |
puts 0 | |
end | |
else | |
puts 2 ** (n - 1) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n, a, b, c, d = gets.chomp.split(" ").map(&:to_i) | |
(0...n).each do |k| | |
if k * c - (n - 1 - k) * d <= b - a && k * d - (n - 1 - k) * c >= b - a then | |
puts "YES" | |
exit | |
end | |
end | |
puts "NO" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment