Skip to content

Commit 73c4891

Browse files
committed
109차 2번 문제풀이(참고)
1 parent f706925 commit 73c4891

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

live10/test109/문제1/박희경.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@
55
n, m = map(int, input().split())
66
a = list(map(int, input().split()))
77

8-
start, end = 0, 0
9-
total = a[0]
10-
cnt = 0
11-
while start <= end:
12-
if total % m == 0:
13-
cnt += 1
8+
remain = [0] * m # 나머지 개수
9+
prefix_sum = 0
10+
for i in range(n):
11+
prefix_sum += a[i]
12+
remain[prefix_sum % m] += 1
1413

15-
total -= a[start]
16-
start += 1
17-
end += 1
18-
if end < n:
19-
total += a[end]
14+
res = remain[0]
15+
# 나머지가 같은 구간 2개를 뽑으면 나머지가 0이 됨
16+
for r in remain:
17+
# 조합; rC2 = r(r-1) / 2
18+
res += r * (r - 1) // 2
19+
20+
print(res)
21+
22+
"""
23+
5 3
24+
1 2 3 1 2
25+
"""

0 commit comments

Comments
 (0)