Submission #3010336


Source Code Expand

Copy
lines = $stdin.read
array = lines.split("\n")

N,M = array[0].split(" ").map(&:to_i)
A = array[1].split(" ").map(&:to_i)
sums = 0
nums = {}

nums[0] = 1
A.each.with_index do |e,i|
  sums += e
  # count mods
  if nums[sums % M].nil?
    nums[sums % M] = 1
  else
    nums[sums % M] += 1
  end
end

#p A
#p nums

ans = 0
nums.each do |k,v|
  ans += v*(v-1)/2
end

puts ans

Submission Info

Submission Time
Task D - Candy Distribution
User hiroyuking
Language Ruby (2.3.3)
Score 400
Code Size 397 Byte
Status
Exec Time 92 ms
Memory 12668 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01, sample_02, sample_03
All 400 / 400 0_min0, 0_min1, 1_small0, 1_small1, 1_small2, 2_large0, 2_large1, 2_large2, 2_large3, 2_large4, 2_large5, 2_large6, 2_large7, 2_large8, 2_large9, 3_max0, 3_max1, 3_max2, 3_max3, 3_max4, 3_max5, 3_max6, 3_max7, sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
0_min0 9 ms 1916 KB
0_min1 7 ms 1788 KB
1_small0 7 ms 1788 KB
1_small1 7 ms 1788 KB
1_small2 7 ms 1788 KB
2_large0 8 ms 1916 KB
2_large1 76 ms 9084 KB
2_large2 63 ms 7804 KB
2_large3 47 ms 5884 KB
2_large4 70 ms 8316 KB
2_large5 18 ms 2684 KB
2_large6 58 ms 7164 KB
2_large7 54 ms 6652 KB
2_large8 8 ms 1788 KB
2_large9 32 ms 4220 KB
3_max0 92 ms 12668 KB
3_max1 76 ms 9212 KB
3_max2 76 ms 9212 KB
3_max3 68 ms 7932 KB
3_max4 67 ms 7932 KB
3_max5 67 ms 7932 KB
3_max6 77 ms 9468 KB
3_max7 77 ms 9468 KB
sample_01 7 ms 1788 KB
sample_02 7 ms 1788 KB
sample_03 7 ms 1788 KB