結果
問題 | No.424 立体迷路 |
ユーザー | mkawa2 |
提出日時 | 2019-12-29 19:14:06 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 529 ms / 2,000 ms |
コード長 | 1,569 bytes |
コンパイル時間 | 92 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 45,012 KB |
最終ジャッジ日時 | 2024-11-06 09:26:06 |
合計ジャッジ時間 | 16,285 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
from itertools import * from bisect import * #from math import * from collections import * from heapq import * from random import * from decimal import * import numpy as np import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 int2 = lambda x: int(x) +1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def MI1(): return map(int1, sys.stdin.readline().split()) def MI2(): return map(int2, sys.stdin.readline().split()) def MF(): return map(float, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LI1(): return list(map(int1, sys.stdin.readline().split())) def LF(): return list(map(float, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] dij = [(1, 0), (0, 1), (-1, 0), (0, -1)] def main(): def dfs(i,j): if (i,j)==(gi,gj):return True h0=t[i][j] t[i][j]=-1 for di,dj in dij: ni,nj=i+di,j+dj ni2,nj2=i+di*2,j+dj*2 h1=t[ni][nj] if h1!=-1 and -1<=h0-h1<=1: if dfs(ni,nj):return True h2=t[ni2][nj2] if h2!=-1 and h2==h0 and h2>h1: if dfs(ni2,nj2):return True return False h,w=MI() si,sj,gi,gj=MI2() t=[[100]*(w+4) for _ in range(2)]+[[100,100]+[int(c) for c in input()]+[100,100] for _ in range(h)]+[[100]*(w+4) for _ in range(2)] #p2D(t) if dfs(si,sj):print("YES") else:print("NO") #p2D(t) main()