[SWEA] Ladder2

Date:

[SWEA] Ladder2

Problem URL : Ladder2

for tc in range(1, 11):
    tc = int(input())
    arr = [list(map(int, input().split())) for _ in range(100)]
    minCost = 1e9
    ans = 0
    for i in range(100):
        if arr[0][i] == 1:
            idx = i
            cnt = 0
            for j in range(100):
                if idx > 0 and arr[j][idx - 1] == 1:
                    while idx > 0 and arr[j][idx - 1] > 0:
                        idx -= 1
                        cnt += 1
                elif idx < 99 and arr[j][idx + 1] == 1:
                    while idx < 99 and arr[j][idx + 1] > 0:
                        idx += 1
                        cnt += 1
            if minCost >= cnt:
                minCost = cnt
                ans = i

    print('#{} {}'.format(tc, ans))

댓글