답안 #377847

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
377847 2021-03-15T10:38:36 Z dia312 배열 탈출 (GA8_array) Python 3
49 / 100
1276 ms 65540 KB
import sys
input=sys.stdin.readline
INF = int(1e9)

n = int(input())
maps = []
maps.append([INF]*(n+1))
#배열 입력 
for i in range(n):
    tmp = [INF]+list(map(int,input().split()))
    maps.append(tmp)

#비용 초기화
cost = [[0 for _ in range(n+1)] for _ in range(n+1)]

cost[1][1]=0

def cal(a,b):
    if a>b:
        return 0
    else:
        return b-a+1

#디피 
for i in range(1,n+1):
    for j in range(1,n+1):
            if j-1==0 and i-1==0:
                continue
            elif j-1==0:
                button2 = cal(maps[i-1][j],maps[i][j]) + cost[i-1][j]
                cost[i][j]+=button2
            elif i-1==0:
                button1 = cal(maps[i][j-1],maps[i][j]) + cost[i][j-1]
                cost[i][j]+=button1  
            else:
                button1 = cal(maps[i][j-1],maps[i][j]) + cost[i][j-1]
                button2 = cal(maps[i-1][j],maps[i][j]) + cost[i-1][j]
                cost[i][j]+=min(button1,button2)
# for i in range(n+1):
#     for j in range(n+1):
#         print(cost[i][j],end=" ")
#     print('')
print(cost[n][n])   
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 2924 KB Output is correct
2 Correct 16 ms 2924 KB Output is correct
3 Correct 17 ms 2924 KB Output is correct
4 Correct 17 ms 2924 KB Output is correct
5 Correct 16 ms 2924 KB Output is correct
6 Correct 16 ms 2924 KB Output is correct
7 Correct 17 ms 2924 KB Output is correct
8 Correct 17 ms 2924 KB Output is correct
9 Correct 16 ms 2924 KB Output is correct
10 Correct 17 ms 2924 KB Output is correct
11 Correct 16 ms 2924 KB Output is correct
12 Correct 17 ms 2924 KB Output is correct
13 Correct 17 ms 2924 KB Output is correct
14 Correct 17 ms 2924 KB Output is correct
15 Correct 17 ms 2924 KB Output is correct
16 Correct 16 ms 2924 KB Output is correct
17 Correct 17 ms 2924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 2924 KB Output is correct
2 Correct 16 ms 2924 KB Output is correct
3 Correct 17 ms 2924 KB Output is correct
4 Correct 17 ms 2924 KB Output is correct
5 Correct 17 ms 2924 KB Output is correct
6 Correct 17 ms 2924 KB Output is correct
7 Correct 16 ms 2924 KB Output is correct
8 Correct 16 ms 2924 KB Output is correct
9 Correct 17 ms 2924 KB Output is correct
10 Correct 17 ms 2924 KB Output is correct
11 Correct 18 ms 3052 KB Output is correct
12 Correct 17 ms 2924 KB Output is correct
13 Correct 16 ms 2924 KB Output is correct
14 Correct 16 ms 2924 KB Output is correct
15 Correct 17 ms 2924 KB Output is correct
16 Correct 17 ms 3052 KB Output is correct
17 Correct 16 ms 2924 KB Output is correct
18 Correct 17 ms 3052 KB Output is correct
19 Correct 16 ms 2924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 138 ms 5356 KB Output is correct
2 Correct 146 ms 5356 KB Output is correct
3 Correct 140 ms 5356 KB Output is correct
4 Correct 140 ms 5504 KB Output is correct
5 Correct 140 ms 5356 KB Output is correct
6 Correct 141 ms 5380 KB Output is correct
7 Correct 135 ms 5296 KB Output is correct
8 Correct 141 ms 5356 KB Output is correct
9 Correct 143 ms 5356 KB Output is correct
10 Correct 149 ms 5356 KB Output is correct
11 Correct 143 ms 5356 KB Output is correct
12 Correct 140 ms 5356 KB Output is correct
13 Correct 140 ms 5356 KB Output is correct
14 Correct 133 ms 5100 KB Output is correct
15 Correct 134 ms 4588 KB Output is correct
16 Correct 140 ms 5356 KB Output is correct
17 Correct 143 ms 5228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1276 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -