結果

問題 No.424 立体迷路
ユーザー rocoderrocoder
提出日時 2017-08-06 12:05:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,924 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 10,980 KB
実行使用メモリ 8,212 KB
最終ジャッジ日時 2023-09-18 17:02:22
合計ジャッジ時間 1,771 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,080 KB
testcase_01 AC 17 ms
8,032 KB
testcase_02 AC 17 ms
8,036 KB
testcase_03 AC 17 ms
8,032 KB
testcase_04 AC 18 ms
8,068 KB
testcase_05 AC 16 ms
8,024 KB
testcase_06 AC 17 ms
8,032 KB
testcase_07 AC 17 ms
8,108 KB
testcase_08 AC 16 ms
8,036 KB
testcase_09 AC 16 ms
8,160 KB
testcase_10 AC 17 ms
8,028 KB
testcase_11 AC 17 ms
8,024 KB
testcase_12 AC 17 ms
8,020 KB
testcase_13 AC 17 ms
8,032 KB
testcase_14 AC 18 ms
8,168 KB
testcase_15 AC 17 ms
8,032 KB
testcase_16 AC 17 ms
8,052 KB
testcase_17 AC 18 ms
8,124 KB
testcase_18 AC 19 ms
8,084 KB
testcase_19 AC 18 ms
8,160 KB
testcase_20 AC 18 ms
8,044 KB
testcase_21 AC 17 ms
8,204 KB
testcase_22 AC 17 ms
8,048 KB
testcase_23 AC 17 ms
8,132 KB
testcase_24 AC 35 ms
8,212 KB
testcase_25 AC 35 ms
8,044 KB
権限があれば一括ダウンロードができます

ソースコード

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)
0