結果
問題 | No.424 立体迷路 |
ユーザー | ayaoni |
提出日時 | 2020-12-18 05:32:00 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 65 ms / 2,000 ms |
コード長 | 1,857 bytes |
コンパイル時間 | 159 ms |
コンパイル使用メモリ | 82,444 KB |
実行使用メモリ | 66,692 KB |
最終ジャッジ日時 | 2024-09-21 08:54:47 |
合計ジャッジ時間 | 2,528 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
56,356 KB |
testcase_01 | AC | 46 ms
54,476 KB |
testcase_02 | AC | 45 ms
54,932 KB |
testcase_03 | AC | 43 ms
54,448 KB |
testcase_04 | AC | 43 ms
55,440 KB |
testcase_05 | AC | 44 ms
54,716 KB |
testcase_06 | AC | 43 ms
54,364 KB |
testcase_07 | AC | 43 ms
54,860 KB |
testcase_08 | AC | 43 ms
55,908 KB |
testcase_09 | AC | 43 ms
54,104 KB |
testcase_10 | AC | 43 ms
53,984 KB |
testcase_11 | AC | 46 ms
55,232 KB |
testcase_12 | AC | 44 ms
54,636 KB |
testcase_13 | AC | 43 ms
54,480 KB |
testcase_14 | AC | 43 ms
55,380 KB |
testcase_15 | AC | 44 ms
55,344 KB |
testcase_16 | AC | 45 ms
54,756 KB |
testcase_17 | AC | 49 ms
60,968 KB |
testcase_18 | AC | 47 ms
60,492 KB |
testcase_19 | AC | 47 ms
61,540 KB |
testcase_20 | AC | 47 ms
60,540 KB |
testcase_21 | AC | 43 ms
54,500 KB |
testcase_22 | AC | 44 ms
56,144 KB |
testcase_23 | AC | 43 ms
54,356 KB |
testcase_24 | AC | 65 ms
66,692 KB |
testcase_25 | AC | 59 ms
66,156 KB |
ソースコード
import sys from collections import deque sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def LS2(): return list(sys.stdin.readline().rstrip()) H,W = MI() sx,sy,gx,gy = MI() B = [[0]*(W+1)]+[[0]+LI2() for _ in range(H)] flag = [[0]*(W+1) for _ in range(H+1)] flag[sx][sy] = 1 deq = deque([(sx,sy)]) while deq: x,y = deq.pop() if 1 <= x-1 <= H and flag[x-1][y] == 0 and abs(B[x-1][y]-B[x][y]) <= 1: flag[x-1][y] = 1 deq.appendleft((x-1,y)) if 1 <= x+1 <= H and flag[x+1][y] == 0 and abs(B[x+1][y]-B[x][y]) <= 1: flag[x+1][y] = 1 deq.appendleft((x+1,y)) if 1 <= y-1 <= W and flag[x][y-1] == 0 and abs(B[x][y-1]-B[x][y]) <= 1: flag[x][y-1] = 1 deq.appendleft((x,y-1)) if 1 <= y+1 <= W and flag[x][y+1] == 0 and abs(B[x][y+1]-B[x][y]) <= 1: flag[x][y+1] = 1 deq.appendleft((x,y+1)) if 1 <= x-2 <= H and flag[x-2][y] == 0 and B[x-2][y] == B[x][y] and B[x-1][y] < B[x][y]: flag[x-2][y] = 1 deq.appendleft((x-2,y)) if 1 <= x+2 <= H and flag[x+2][y] == 0 and B[x+2][y] == B[x][y] and B[x+1][y] < B[x][y]: flag[x+2][y] = 1 deq.appendleft((x+2,y)) if 1 <= y-2 <= W and flag[x][y-2] == 0 and B[x][y-2] == B[x][y] and B[x][y-1] < B[x][y]: flag[x][y-2] = 1 deq.appendleft((x,y-2)) if 1 <= y+2 <= W and flag[x][y+2] == 0 and B[x][y+2] == B[x][y] and B[x][y+1] < B[x][y]: flag[x][y+2] = 1 deq.appendleft((x,y+2)) if flag[gx][gy]: print('YES') else: print('NO')