Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Last active August 23, 2016 04:17
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/5b1cf4fcb1e29b70eb8b49dbb4ad5d1e to your computer and use it in GitHub Desktop.
Save whatalnk/5b1cf4fcb1e29b70eb8b49dbb4ad5d1e to your computer and use it in GitHub Desktop.
AtCoder AGC #003 [Ruby]
# AC
s = gets.chomp
if (s.include?("N") && s.include?("S") && !s.include?("E") && !s.include?("W")) || (!s.include?("N") && !s.include?("S") && s.include?("E") && s.include?("W")) || (s.include?("N") && s.include?("S") && s.include?("E") && s.include?("W")) then
puts "Yes"
else
puts "No"
end
# AC
n = gets.chomp.to_i
a = []
n.times do
a << gets.chomp.to_i
end
ans = 0
n.times do |i|
ans += a[i] / 2
if a[i] % 2 == 1 && i != n - 1 then
if a[i + 1] != 0 then
ans += 1
a[i + 1] -= 1
end
end
end
puts ans
# AC
n = gets.chomp.to_i
a = Hash.new
n.times do |i|
x = gets.chomp.to_i
a[x] = i % 2
end
ans = 0
a.keys.sort.each_with_index do |x, i|
ans += 1 if a[x] != i % 2
end
puts ans / 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment