結果

問題 No.424 立体迷路
ユーザー rocoderrocoder
提出日時 2017-08-06 12:05:36
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 1,924 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-07-05 07:14:50
合計ジャッジ時間 1,456 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

# your code goes here
#rabirynce
def ab(a1):
if a1<0:
a1*=-1
return a1
h,w=(int(i) for i in input().split())
sx,sy,gx,gy=(int(i) for i in input().split())
sx-=1
sy-=1
gx-=1
gy-=1
b=[list(input()) for i in range(h)]
for i in range(h):
for j in range(w):
b[i][j]=int(b[i][j])
vn=[[sx,sy]]
v=[[0,0]]
Nd=0
i=0
a=[]
for i in range(h):
a.append([])
for j in range(w):
a[i].append(0)
a[sx][sy]=1
if sx==gx and sy==gy:
Nd=1
while Nd<1 and vn!=[] and i<h*w+1:
j=0
v=vn
vn=[]
while j<len(v):
tx=v[j][0]
ty=v[j][1]
k=-1
while k<2:
# print(k)
# print("k")
l=-1
while l<2:
if ab(k)+ab(l)<2:
# print(k)
# print(l)
ux=tx+k
uy=ty+l
if ux>=0 and ux<h and uy>=0 and uy<w and a[ux][uy]==0:
# print("u")
if b[tx][ty]==b[ux][uy] or ab(b[tx][ty]-b[ux][uy])==1:
# print(b)
if ux==gx and uy==gy:
Nd=1
a[ux][uy]=1
vn.append([ux,uy])
# print(vn)
elif b[tx][ty]>b[ux][uy]:
u1x=ux+k
u1y=uy+l
# print(u1x)
if u1x>=0 and u1x<h and u1y>=0 and u1y<w and a[u1x][u1y]==0:
if b[tx][ty]==b[u1x][u1y]:
if u1x==gx and u1y==gy:
Nd=1
a[u1x][u1y]=1
vn.append([u1x,u1y])
l+=1
k+=1
j+=1
i+=1
if Nd==1:
p="YES"
else:
p="NO"
print(p)
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0