結果

問題 No.424 立体迷路
ユーザー JunOnumaJunOnuma
提出日時 2017-06-29 16:32:22
言語 Python2
(2.7.18)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 950 bytes
コンパイル時間 48 ms
コンパイル使用メモリ 6,728 KB
実行使用メモリ 6,736 KB
最終ジャッジ日時 2023-09-18 17:01:20
合計ジャッジ時間 1,610 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
6,600 KB
testcase_01 AC 16 ms
6,684 KB
testcase_02 AC 16 ms
6,484 KB
testcase_03 AC 15 ms
6,660 KB
testcase_04 AC 16 ms
6,480 KB
testcase_05 AC 15 ms
6,456 KB
testcase_06 AC 15 ms
6,604 KB
testcase_07 AC 15 ms
6,676 KB
testcase_08 AC 15 ms
6,688 KB
testcase_09 AC 14 ms
6,736 KB
testcase_10 AC 15 ms
6,476 KB
testcase_11 AC 14 ms
6,508 KB
testcase_12 AC 15 ms
6,668 KB
testcase_13 AC 15 ms
6,600 KB
testcase_14 AC 14 ms
6,628 KB
testcase_15 AC 14 ms
6,532 KB
testcase_16 AC 15 ms
6,732 KB
testcase_17 AC 17 ms
6,576 KB
testcase_18 AC 16 ms
6,676 KB
testcase_19 AC 16 ms
6,536 KB
testcase_20 AC 17 ms
6,532 KB
testcase_21 AC 15 ms
6,632 KB
testcase_22 AC 15 ms
6,700 KB
testcase_23 AC 14 ms
6,524 KB
testcase_24 AC 39 ms
6,580 KB
testcase_25 AC 40 ms
6,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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