結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-09-22 23:03:31 |
| 言語 | Python2 (2.7.18) |
| 結果 |
AC
|
| 実行時間 | 18 ms / 2,000 ms |
| コード長 | 1,335 bytes |
| コンパイル時間 | 537 ms |
| コンパイル使用メモリ | 7,040 KB |
| 実行使用メモリ | 8,448 KB |
| 最終ジャッジ日時 | 2024-07-05 07:05:53 |
| 合計ジャッジ時間 | 1,243 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 21 |
ソースコード
#!/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())