Search
Duplicate
๐Ÿฅˆ

์ˆ˜๋“ค์˜ ํ•ฉ 2

์ฃผ์ฐจ
15
๋ฌธ์ œ๋ฒˆํ˜ธ
2003
์–ธ์–ด
Python
ํ‹ฐ์–ด
์‹ค๋ฒ„
์œ ํ˜•
ํˆฌ ํฌ์ธํ„ฐ
nj_Blog
O
nj_์ƒํƒœ
ํ‘ธ๋Š” ์ค‘
์ดํ•ด๋„
ํ’€์ด
์‚ฌ๋žŒ
์ดํ•ด๋„ 2
13 more properties

๋ฌธ์ œ๋งํฌ

https://www.acmicpc.net/problem/2003

์ฝ”๋“œ ์ œ์ถœ ๊ธฐ๋ก (๋ฉ”๋ชจ๋ฆฌ ๋ฐ ์‹œ๊ฐ„)

๋ฉ”๋ชจ๋ฆฌ : 123352 KB
์‹œ๊ฐ„ : 276 ms

Code

def sum_i2j(i, j, arr): answer = 0 for k in range(i, j+1): answer += arr[k] return answer N, M = map(int, input().split()) arr = list(map(int, input().split())) start = 0 end = 0 result = 0 while (start < N and end < N): if (sum_i2j(start, end, arr) == M): result += 1 end += 1 elif (sum_i2j(start, end, arr) < M): end += 1 elif (sum_i2j(start, end, arr) > M): if start == end: end += 1 else: start += 1 print(result)
Python
๋ณต์‚ฌ

๋ฉ”๋ชจ

ํˆฌ ํฌ์ธํ„ฐ ์‚ฌ์šฉ!