답안 #28185

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
28185 2017-07-15T14:24:35 Z 테에스뚜우웅우우우(#1204, owlur) 도시와 비트코인 (FXCUP2_city) Python 3
0 / 1
74 ms 5 KB
N,M = [int(i) for i in input().split()]
map = []
for i in range(M):
    map.append([int(i) for i in input().split()])

dp = [[[0,0,0,0] for i in range(N)] for i in range(M)]

def find_road(index):
    if index[0] >=M or index[0]<0 or index[1] >= N or index[1] <0 or map[index[0]][index[1]] == 0:
        return -1
    elif index[0] == M-1 and index[1] == N-1:
        return 1

    for via, value in enumerate(dp[index[0]][index[1]]):
        if value == 0 :
            if via == 0:
                dp[index[0]][index[1]][0] = -2
                dp[index[0]][index[1]][0] = find_road((index[0], index[1] + 1))
            elif via == 1:
                dp[index[0]][index[1]][1] = -2
                dp[index[0]][index[1]][1] = find_road((index[0] + 1, index[1]))
            elif via == 2:
                dp[index[0]][index[1]][2] = -2
                dp[index[0]][index[1]][2] = find_road((index[0], index[1] - 1))
            else:
                dp[index[0]][index[1]][3] = -2
                dp[index[0]][index[1]][3] = find_road((index[0] - 1, index[1]))

    return max(dp[index[0]][index[1]])


res = find_road((0,0))

if res == 1:
    print('Yes')
else:
    print('No')
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 3 KB Output is correct
2 Correct 31 ms 3 KB Output is correct
3 Correct 29 ms 3 KB Output is correct
4 Runtime error 74 ms 5 KB Execution failed because the return code was nonzero
5 Halted 0 ms 0 KB -