[백준 3699][Python] 주차 빌딩

봉글렛·2023년 1월 15일

백준

목록 보기
36/55

문제 풀이 https://www.acmicpc.net/problem/3699

한 층에서 시계방향으로만이 아닌 반시계로도 이동한다는 점...

from sys import stdin

for _ in range(int(stdin.readline())):
    h, l = map(int, stdin.readline().rstrip().split())
    p_c = {}

    for i in range(h):
        f = list(map(int, stdin.readline().rstrip().split()))
        for j in range(len(f)):
            if f[j] != -1:
                p_c[f[j]] = (i+1, j+1)
    floor = sorted(p_c.items())

    hh = [1] * (h+1)
    result = 0

    for i, j in floor:
        result += abs(1 - j[0]) * 20
        result += min(abs(hh[j[0]] - j[1]), abs(l - abs(hh[j[0]] - j[1]))) * 5
        hh[j[0]] = j[1]
    print(result)
profile
어쩌다 개발자 (할 수 있을 때까지!!!!)

0개의 댓글