Created
July 15, 2018 13:31
-
-
Save whatalnk/b9f08a905b44fbc08f78462493b16dfc to your computer and use it in GitHub Desktop.
AtCoder AGC #023 A
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) | |
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