結果

問題 No.424 立体迷路
ユーザー HachimoriHachimori
提出日時 2016-09-22 23:03:31
言語 Python2
(2.7.18)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,335 bytes
コンパイル時間 44 ms
コンパイル使用メモリ 6,816 KB
実行使用メモリ 8,072 KB
最終ジャッジ日時 2023-09-18 16:50:03
合計ジャッジ時間 1,451 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
5,952 KB
testcase_01 AC 12 ms
5,984 KB
testcase_02 AC 12 ms
5,896 KB
testcase_03 AC 12 ms
6,024 KB
testcase_04 AC 12 ms
5,984 KB
testcase_05 AC 11 ms
6,028 KB
testcase_06 AC 11 ms
5,852 KB
testcase_07 AC 11 ms
6,028 KB
testcase_08 AC 11 ms
5,984 KB
testcase_09 AC 12 ms
5,980 KB
testcase_10 AC 11 ms
6,048 KB
testcase_11 AC 11 ms
5,940 KB
testcase_12 AC 12 ms
5,980 KB
testcase_13 AC 12 ms
5,932 KB
testcase_14 AC 11 ms
5,912 KB
testcase_15 AC 12 ms
5,840 KB
testcase_16 AC 11 ms
6,024 KB
testcase_17 AC 12 ms
6,064 KB
testcase_18 AC 12 ms
5,976 KB
testcase_19 AC 13 ms
5,976 KB
testcase_20 AC 13 ms
5,952 KB
testcase_21 AC 11 ms
5,840 KB
testcase_22 AC 12 ms
5,960 KB
testcase_23 AC 12 ms
5,840 KB
testcase_24 AC 13 ms
6,140 KB
testcase_25 AC 23 ms
8,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

import sys
sys.setrecursionlimit(3000)


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