結果
問題 | No.424 立体迷路 |
ユーザー |
![]() |
提出日時 | 2016-09-22 23:07:58 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 55 ms / 2,000 ms |
コード長 | 1,000 bytes |
コンパイル時間 | 125 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-07-05 07:06:03 |
合計ジャッジ時間 | 1,514 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
H,W = map(int,input().split())sy,sx,gy,gx = map(int,input().split())sx,sy,gx,gy = sx - 1,sy-1,gx-1,gy-1b = [input() for i in range(H)]used = [[False for j in range(W)]for i in range(H)]dx = [0,0,-1,1]dy = [1,-1,0,0]q = [(sy,sx)]flag = Falsewhile len(q) > 0:d = q.pop(0)if used[d[0]][d[1]]:continueused[d[0]][d[1]] = Trueif d[0] == gy and d[1] == gx:print('YES')flag = Truebreakfor i in range(4):nx = dx[i] + d[1]ny = dy[i] + d[0]if nx < 0 or ny < 0 or nx >= W or ny >= H:continueif b[ny][nx] == b[d[0]][d[1]]:q.append([ny,nx])if abs(int(b[ny][nx]) - int(b[d[0]][d[1]])) == 1:q.append([ny,nx])for i in range(4):nx = dx[i] + d[1]ny = dy[i] + d[0]nnx = dx[i] * 2 + d[1]nny = dy[i] * 2 + d[0]if nnx < 0 or nny < 0 or nnx >= W or nny >= H:continueif nx < 0 or ny < 0 or nx >= W or ny >= H:continueif b[nny][nnx] == b[d[0]][d[1]] and int(b[nny][nnx]) > int(b[ny][nx]):q.append([nny,nnx])if not flag:print('NO')