Study/알고리즘

[백준] 1551번_수열의변화

혤리 2020. 2. 2. 20:54

문제 링크 : https://www.acmicpc.net/problem/1551

 

1551번: 수열의 변화

첫째 줄에 수열의 크기 N과 K가 주어진다. N은 20보다 작거나 같은 자연수이고, K는 0보다 크거나 같고, N-1보다 작거나 같은 자연수이다. 둘째 줄에는 수열이 ‘,’로 구분되어 주어진다.

www.acmicpc.net

from copy import deepcopy

n, k = map(int,input().split())
arr = list(map(int,input().split(',')))
while k:
    tmp = []
    for i in range(1,len(arr)):
        tmp.append(arr[i]-arr[i-1])
    arr = deepcopy(tmp)
    k-=1
print(','.join(map(str,arr)))

여기선 굳이 deepcopy를 안써도 된다. (안쓰는게 조금 더 빠르다)