Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created September 11, 2017 05:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatalnk/7d2a3175a8f79d662698a966b0810bb9 to your computer and use it in GitHub Desktop.
Save whatalnk/7d2a3175a8f79d662698a966b0810bb9 to your computer and use it in GitHub Desktop.
AtCoder ABC #073
n = gets.chomp.split("")
n.each do |i|
if i == "9"
puts "Yes"
exit
end
end
puts "No"
n = gets.chomp.to_i
ans = 0
n.times do
l, r = gets.chomp.split(" ").map(&:to_i)
ans += (r - l + 1)
end
puts ans
n = gets.chomp.to_i
h = Hash.new(0)
n.times do
a = gets.chomp.to_i
h[a] += 1
end
ans = 0
h.each do |k, v|
if v.odd?
ans += 1
end
end
puts ans
n, m, r = gets.chomp.split(" ").map(&:to_i)
rr = gets.chomp.split(" ").map(&:to_i)
MAX_C = 2 << 31
g = Array.new(n+1){Array.new(n+1, MAX_C)}
(n+1).times do |i|
g[i][i] = 0
end
m.times do
a, b, c = gets.chomp.split(" ").map(&:to_i)
g[a][b] = c
g[b][a] = c
end
# Warshall floyd
1.upto(n) do |k|
1.upto(n) do |i|
1.upto(n) do |j|
g[i][j] = g[i][k] + g[k][j] if g[i][k] + g[k][j] < g[i][j]
end
end
end
ans = []
rr.permutation do |x|
dist = 0
(r-1).times do |i|
dist += g[x[i]][x[i+1]]
end
ans << dist
end
puts ans.min
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment