結果

問題 No.424 立体迷路
ユーザー Hachimori
提出日時 2016-09-22 23:02:26
言語 Python2
(2.7.18)
結果
RE  
実行時間 -
コード長 1,294 bytes
コンパイル時間 875 ms
コンパイル使用メモリ 7,204 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-11-17 15:05:16
合計ジャッジ時間 898 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 20 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python
#coding:utf8

def read():
    row, col = map(int, raw_input().split())
    sr, sc, gr, gc = map(int, raw_input().split())
    sr -= 1
    sc -= 1
    gr -= 1
    gc -= 1
    
    b = []
    for i in range(row):
        b.append(map(int, raw_input()))
    return row, col, sr, sc, gr, gc, b


def dfs(r, c, visited, gr, gc, b):
    if r == gr and c == gc:
        return True
    visited[r][c] = True
    for dr, dc in [(-1, 0), (0, 1), (1, 0), (0, -1)]:
        nr = r + dr
        nc = c + dc
        nr2 = r + dr * 2
        nc2 = c + dc * 2
        
        if (0 <= nr < len(visited) and 0 <= nc < len(visited[0])) and \
           not visited[nr][nc] and \
           abs(b[nr][nc] - b[r][c]) <= 1 and dfs(nr, nc, visited, gr, gc, b):
            return True

        if (0 <= nr2 < len(visited) and 0 <= nc2 < len(visited[0])) and \
           not visited[nr2][nc2] and \
           b[nr][nc] <= b[r][c] and b[nr2][nc2] == b[r][c] and dfs(nr2, nc2, visited, gr, gc, b):
            return True
        
    return False    


def work((row, col, sr, sc, gr, gc, b)):
    visited = [[False for c in range(col)] for r in range(row)]
    if dfs(sr, sc, visited, gr, gc, b):
        print "YES"
    else:
        print "NO"


if __name__ == "__main__":
    work(read())
0