結果

問題 No.424 立体迷路
ユーザー gahougahou
提出日時 2016-10-28 18:34:46
言語 Python2
(2.7.18)
結果
RE  
実行時間 -
コード長 1,041 bytes
コンパイル時間 76 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 7,040 KB
最終ジャッジ日時 2024-05-03 07:17:59
合計ジャッジ時間 1,323 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 AC 14 ms
6,912 KB
testcase_04 WA -
testcase_05 AC 16 ms
6,912 KB
testcase_06 AC 15 ms
6,912 KB
testcase_07 AC 15 ms
6,912 KB
testcase_08 AC 14 ms
6,912 KB
testcase_09 WA -
testcase_10 AC 14 ms
6,784 KB
testcase_11 AC 14 ms
6,912 KB
testcase_12 AC 14 ms
6,784 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 15 ms
6,912 KB
testcase_17 WA -
testcase_18 AC 17 ms
6,912 KB
testcase_19 AC 17 ms
6,912 KB
testcase_20 AC 18 ms
6,784 KB
testcase_21 AC 14 ms
6,784 KB
testcase_22 AC 15 ms
6,784 KB
testcase_23 WA -
testcase_24 AC 38 ms
6,912 KB
testcase_25 AC 38 ms
6,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import Queue

h,w = map(int, raw_input().split())
sy,sx,gy,gx = map(int, raw_input().split())
sx-=1
sy-=1
gx-=1
gy-=1
dist = [[0,1], [0,-1], [1,0], [-1,0]]
blocks = [[0]*w for _ in xrange(h)]
checked = [[False]*w for _ in xrange(h)]
for i in xrange(h):
  b = raw_input()
  for j in xrange(w):
    blocks[i][j] = int(b[j])
q = Queue.Queue()
q.put([sx, sy])
checked[sx][sy] = True

reach = False
counter = 0
while q.qsize() > 0:
  counter += 1
  pos = q.get()
  if pos[0]==gx and pos[1]==gy:
    reach = True
    break
  for d in dist:
    x = pos[0]+d[0]
    y = pos[1]+d[1]
    if x<0 or y<0 or h<=x or w<=y or checked[x][y]: continue
    if abs(blocks[pos[0]][pos[1]]-blocks[x][y]) <= 1 and checked[x][y]==False:
      q.put([x, y])
      checked[x][y] = True
  for d in dist:
    x = pos[0]+d[0]*2
    y = pos[1]+d[1]*2
    if x<0 or y<0 or h<=x or w<=y or checked[x][y]: continue
    if blocks[pos[0]][pos[1]] >= blocks[x][y] and checked[x][y]==False:
      q.put([x, y])
      checked[x][y] = True

if reach: print "YES"
else: print "NO"
0