Today
Total
06-28 22:01
관리 메뉴

홍우진의 개발 일기장

[백준] 2018번: 수들의 합 5 / 파이썬 본문

알고리즘/백준

[백준] 2018번: 수들의 합 5 / 파이썬

홍우진 2025. 2. 7. 23:48
728x90
반응형

문제 링크


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

풀이 코드


n = int(input())
cnt, tot, start, end = 0, 0, 0, 0

while end <= n:
    if tot < n:
        end += 1
        tot += end
        
    elif tot > n:
        start += 1
        tot -= start

    else:
        cnt += 1
        end += 1
        tot += end

print(cnt)

코드 해석


투 포인터 알고리즘을 활용하였다.

 

 

체감 난이도: ★☆☆☆

728x90
반응형
Comments