結果
問題 | No.424 立体迷路 |
ユーザー |
|
提出日時 | 2016-10-28 18:40:52 |
言語 | Python2 (2.7.18) |
結果 |
AC
|
実行時間 | 40 ms / 2,000 ms |
コード長 | 1,083 bytes |
コンパイル時間 | 462 ms |
コンパイル使用メモリ | 6,912 KB |
実行使用メモリ | 7,040 KB |
最終ジャッジ日時 | 2024-07-05 07:11:35 |
合計ジャッジ時間 | 1,617 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
import Queueh,w = map(int, raw_input().split())sx,sy,gx,gy = map(int, raw_input().split())sx-=1sy-=1gx-=1gy-=1dist = [[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] = Truereach = Falsecounter = 0while q.qsize() > 0:counter += 1pos = q.get()if pos[0]==gx and pos[1]==gy:reach = Truebreakfor 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]: continueif abs(blocks[pos[0]][pos[1]]-blocks[x][y]) <= 1 and checked[x][y]==False:q.put([x, y])checked[x][y] = Truefor d in dist:x = pos[0]+d[0]*2y = pos[1]+d[1]*2if x<0 or y<0 or h<=x or w<=y or checked[x][y]: continueif 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] = Trueif reach: print "YES"else: print "NO"