結果

問題 No.424 立体迷路
ユーザー gahougahou
提出日時 2016-10-28 18:40:52
言語 Python2
(2.7.18)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,083 bytes
コンパイル時間 664 ms
コンパイル使用メモリ 6,548 KB
実行使用メモリ 6,736 KB
最終ジャッジ日時 2023-09-18 16:57:44
合計ジャッジ時間 2,169 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
6,600 KB
testcase_01 AC 15 ms
6,480 KB
testcase_02 AC 15 ms
6,696 KB
testcase_03 AC 16 ms
6,736 KB
testcase_04 AC 16 ms
6,692 KB
testcase_05 AC 15 ms
6,484 KB
testcase_06 AC 15 ms
6,668 KB
testcase_07 AC 15 ms
6,692 KB
testcase_08 AC 15 ms
6,664 KB
testcase_09 AC 15 ms
6,608 KB
testcase_10 AC 15 ms
6,668 KB
testcase_11 AC 15 ms
6,604 KB
testcase_12 AC 15 ms
6,484 KB
testcase_13 AC 15 ms
6,608 KB
testcase_14 AC 15 ms
6,524 KB
testcase_15 AC 15 ms
6,488 KB
testcase_16 AC 16 ms
6,532 KB
testcase_17 AC 16 ms
6,568 KB
testcase_18 AC 16 ms
6,568 KB
testcase_19 AC 16 ms
6,516 KB
testcase_20 AC 16 ms
6,736 KB
testcase_21 AC 15 ms
6,516 KB
testcase_22 AC 16 ms
6,536 KB
testcase_23 AC 15 ms
6,484 KB
testcase_24 AC 41 ms
6,592 KB
testcase_25 AC 40 ms
6,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import Queue

h,w = map(int, raw_input().split())
sx,sy,gx,gy = 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 blocks[x][y] > blocks[x-d[0]][y-d[1]] and checked[x][y]==False:
      q.put([x, y])
      checked[x][y] = True

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