結果

問題 No.424 立体迷路
ユーザー pluto77pluto77
提出日時 2018-01-27 11:03:05
言語 Python2
(2.7.18)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 936 bytes
コンパイル時間 84 ms
コンパイル使用メモリ 6,708 KB
実行使用メモリ 6,712 KB
最終ジャッジ日時 2023-09-18 17:02:51
合計ジャッジ時間 1,578 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
6,580 KB
testcase_01 AC 15 ms
6,604 KB
testcase_02 AC 15 ms
6,580 KB
testcase_03 AC 14 ms
6,700 KB
testcase_04 AC 15 ms
6,488 KB
testcase_05 AC 14 ms
6,496 KB
testcase_06 AC 14 ms
6,488 KB
testcase_07 AC 14 ms
6,648 KB
testcase_08 AC 15 ms
6,540 KB
testcase_09 AC 14 ms
6,640 KB
testcase_10 AC 14 ms
6,712 KB
testcase_11 AC 14 ms
6,528 KB
testcase_12 AC 14 ms
6,528 KB
testcase_13 AC 14 ms
6,636 KB
testcase_14 AC 15 ms
6,652 KB
testcase_15 AC 14 ms
6,640 KB
testcase_16 AC 15 ms
6,484 KB
testcase_17 AC 16 ms
6,540 KB
testcase_18 AC 15 ms
6,520 KB
testcase_19 AC 16 ms
6,692 KB
testcase_20 AC 16 ms
6,536 KB
testcase_21 AC 15 ms
6,500 KB
testcase_22 AC 15 ms
6,700 KB
testcase_23 AC 14 ms
6,704 KB
testcase_24 AC 40 ms
6,528 KB
testcase_25 AC 40 ms
6,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#yuki424
import Queue

h,w = map(int, raw_input().split())
sx,sy,gx,gy = map(int, raw_input().split())
sx,sy,gx,gy=sx-1,sy-1,gx-1,gy-1
l=[]
for i in xrange(h):
 l.append(map(int,list(raw_input())))
ls = [[True for i in range(w)] for j in range(h)]
q = Queue.Queue()
q.put((sx,sy))
ls[sx][sy] = False
f = False
while not q.empty():
    x,y = q.get()
    if x == gx and y == gy:
        f = True
        break;
    for dx,dy in [(-1,0),(1,0),(0,-1),(0,1)]:
        if 0 <= x+dx and x+dx < h and 0 <= y+dy and y+dy < w and ls[x+dx][y+dy] and abs(l[x][y] - l[x+dx][y+dy]) < 2:
            q.put((x+dx,y+dy))
            ls[x+dx][y+dy] = False
    for dx,dy in [(-2,0),(2,0),(0,-2),(0,2)]:
        if 0 <= x+dx and x+dx < h and 0 <= y+dy and y+dy < w and ls[x+dx][y+dy] and l[x][y] == l[x+dx][y+dy] and l[x+dx/2][y+dy/2] < l[x][y]:
            q.put((x+dx,y+dy))
            ls[x+dx][y+dy] = False
if f:
    print 'YES'
else:
    print 'NO'
0