Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created July 15, 2018 13:31
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/b9f08a905b44fbc08f78462493b16dfc to your computer and use it in GitHub Desktop.
Save whatalnk/b9f08a905b44fbc08f78462493b16dfc to your computer and use it in GitHub Desktop.
AtCoder AGC #023 A
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
s = [0]
n.times do |i|
s[i+1] = s[i] + a[i]
end
h = Hash.new(0)
s.each do |i|
h[i] += 1
end
ans = 0
h.each do |k, v|
if v == 1
next
elsif v == 2
ans += 1
else
ans += (v * (v - 1) / 2)
end
end
puts ans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment