Submission #28185

#TimeUsernameProblemLanguageResultExecution timeMemory
28185테에스뚜우웅우우우 (#71)The City and The Bitcoin (FXCUP2_city)Cpython 3
0 / 1
74 ms5 KiB
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')
#Verdict Execution timeMemoryGrader output
Fetching results...