Algorithm(CodeTree, Python)127 [코드트리 자리 수 단위로 완전탐색] 모이자 python # n 입력 n = int(input()) # ppl_list 입력 ppl_list = list(map(int, input().split())) # 함수들 # search(k) def search(k): # dist 설정 dist = 0 # 거리구하기 for idx in range(n): dist += abs(idx - k) * ppl_list[idx] # 반환 return dist # 설계 # 최소 거리 import sys short_cut = sys.maxsize # 완전 탐색 for i in range(n): # 탐색 curr_dist = search(i) # 최솟값 갱신 short_cut = min(short_cut, curr_dist) # 출력 print(short_cut) 2022. 11. 1. 이전 1 ··· 5 6 7 8 다음