Last active
July 3, 2016 00:35
-
-
Save whatalnk/4771f905ac3e4fb739dbdc52fb7eb9ae to your computer and use it in GitHub Desktop.
AtCoder ABC #041 (Ruby)
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
s = gets.chomp | |
i = gets.chomp.to_i | |
puts s[i-1] |
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
a, b, c = gets.chomp.split(" ").map(&:to_i) | |
f = 10**9 + 7 | |
puts a * b * c % f |
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 = gets.chomp.to_i | |
a = gets.chomp.split(" ").map(&:to_i) | |
a.zip((1..n).to_a).sort{|x, y| -(x[0] <=> y[0])}.each do |b| | |
puts b[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
# http://abc041.contest.atcoder.jp/submissions/791292 | |
# http://abc041.contest.atcoder.jp/submissions/790956 | |
n, m = gets.chomp.split(" ").map(&:to_i) | |
x = [] | |
y = [] | |
m.times do | |
line = gets.chomp.split(" ").map(&:to_i) | |
x << line[0] - 1 | |
y << line[1] - 1 | |
end | |
valid = [] | |
dp = Array.new(1<<16, 0) | |
nn = (1<<n) | |
def contain(mask, pos) | |
return !(mask & (1<<pos)).zero? | |
end | |
nn.times do |mask| | |
valid[mask] = true | |
m.times do |i| | |
if contain(mask, y[i]) && !contain(mask, x[i]) then | |
valid[mask] = false | |
break | |
end | |
end | |
end | |
dp[0] = 1 | |
nn.times do |mask| | |
if valid[mask] then | |
n.times do |i| | |
if contain(mask, i) && valid[mask^(1<<i)] then | |
dp[mask] += dp[mask^(1<<i)] | |
end | |
end | |
end | |
end | |
puts dp[nn - 1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment