Softeer: 복잡한 조립라인1

2021. 10. 19. 17:38Algorithm

    목차
반응형

 

import sys
import collections


K, N = map(int, sys.stdin.readline().split())

grid = []
tran = []

for i in range(N - 1):
    line = list(map(int, sys.stdin.readline().split()))
    grid += line[:K],
    pos = 0
    tran_map = collections.defaultdict(int)

    for j in range(K):
        for k in range(K):
            if j == k:
                continue

            tran_map[(j, k)] = line[K + pos]
            pos += 1

    tran += tran_map,

line = list(map(int, sys.stdin.readline().split()))
grid += line,

for i in range(N - 1):
    for j in range(K):
        mn = grid[i][j]

        for k in range(K):
            if j == k:
                continue
            mn = min(mn, grid[i][k] + tran[i][(k, j)])

        grid[i + 1][j] += mn


print(min(grid[-1]))

 

 

반응형

'Algorithm' 카테고리의 다른 글

Softeer: 수퍼바이러스  (0) 2021.10.21
Softeer: 복잡한 조립라인2  (0) 2021.10.19
Softeer: 로봇이 지나간 경로  (0) 2021.10.15
Softeer: 징검다리2  (0) 2021.10.14
Softeer: H-클린알파  (0) 2021.10.13