結果
問題 |
No.424 立体迷路
|
ユーザー |
![]() |
提出日時 | 2018-08-11 16:25:07 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 871 bytes |
コンパイル時間 | 96 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,648 KB |
最終ジャッジ日時 | 2024-09-23 06:16:30 |
合計ジャッジ時間 | 1,865 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 20 RE * 1 |
ソースコード
H,W = map(int,input().split()) sh,sw,gh,gw = map(int,input().split()) INF = float("inf") maze = [[INF]*(W+2)] memo = [[1 for i in range(W+2)]for j in range(H+2)] def search(h,w): if h==gh and w==gw: print("YES") exit(0) now = maze[h][w] for i in [[1,0],[0,1],[-1,0],[0,-1]]: nh,nw = h+i[0],w+i[1] if memo[nh][nw] and (maze[nh][nw]==now or maze[nh][nw]==now-1 or maze[nh][nw]==now+1): memo[nh][nw]=0 search(nh,nw) nnh,nnw = nh+i[0],nw+i[1] if nnh>=0 and nnh<=H and nnw>0 and nnw<=W: if maze[nh][nw]<now and maze[nnh][nnw]==now and memo[nnh][nnw]: memo[nnh][nnw]=0 search(nnh,nnw) for i in range(H): l = list(input()) l = map(int,l) maze.append([INF]+list(l)+[INF]) maze.append([INF]*(W+2)) memo[sh][sw]=0 search(sh,sw) print("NO")