結果

問題 No.424 立体迷路
ユーザー kitayan
提出日時 2016-10-05 08:57:36
言語 Python2
(2.7.18)
結果
RE  
実行時間 -
コード長 2,679 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 7,168 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2024-11-21 17:13:27
合計ジャッジ時間 1,150 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 5
other RE * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#!usr/bin/env python
# -*- coding:utf-8 -*-

import numpy as np
import math

def move(sx,sy,b,gx,gy):
    flag[sx-1,sy-1] = 1
    #print sx,sy
    if sx+1 <= h and flag[sx,sy-1] == 0:
        if math.fabs(b[sx-1,sy-1]-b[sx,sy-1]) <= 1:
            if sx+1 == gx and sy == gy:
                return 1
            else:
                if move(sx+1,sy,b,gx,gy):
                    return 1
    if sx-1 > 0 and flag[sx-2,sy-1] == 0:
        if math.fabs(b[sx-1,sy-1]-b[sx-2,sy-1]) <= 1:
            if sx-1 == gx and sy == gy:
                return 1
            else:
                if move(sx-1,sy,b,gx,gy):
                    return 1
    if sy+1 <= w and flag[sx-1,sy] == 0:
        if math.fabs(b[sx-1,sy-1]-b[sx-1,sy]) <= 1:
            if sy+1 == gy and sx == gx:
                return 1
            else:
                if move(sx,sy+1,b,gx,gy):
                    return 1
    if sy-1 > 0 and flag[sx-1,sy-2] == 0:
        if math.fabs(b[sx-1,sy-1]-b[sx-1,sy-2]) <= 1:
            if sx == gx and sy-1 == gy:
                return 1
            else:
                if move(sx,sy-1,b,gx,gy):
                    return 1
    if sx+2 <= h and flag[sx+1,sy-1] == 0:
        if b[sx-1,sy-1] == b[sx+1,sy-1] and b[sx-1,sy-1] > b[sx,sy-1]:
            if sx+2 == gx and sy == gy:
                return 1
            else:
                if move(sx+2,sy,b,gx,gy):
                    return 1
    if sx-2 > 0 and flag[sx-3,sy-1] == 0:
        if b[sx-1,sy-1] == b[sx-3,sy-1] and b[sx-1,sy-1] > b[sx-2,sy-1]:
            if sx-2 == gx and sy == gy:
                return 1
            else:
                if move(sx-2,sy,b,gx,gy):
                    return 1
    if sy+2 <= w and flag[sx-1,sy+1] == 0:
        if b[sx-1,sy-1] == b[sx-1,sy+1] and b[sx-1,sy-1] > b[sx-1,sy]:
            if sx == gx and sy+2 == gy:
                return 1
            else:
                if move(sx,sy+2,b,gx,gy):
                    return 1
    if sy-2 > 0 and flag[sx-1,sy-3] == 0:
        if b[sx-1,sy-1] == b[sx-1,sy-3] and b[sx-1,sy-1] > b[sx-1,sy-2]:
            if sx == gx and sy-2 == gy:
                return 1
            else:
                if move(sx,sy-2,b,gx,gy):
                    return 1

    return 0

if __name__ == '__main__':
    S  = raw_input().split()
    SG = raw_input().split()
    for i in range(h):
        B = raw_input()
    h = int(S[0])
    w = int(S[1])
    
    sx = int(SG[0])
    sy = int(SG[1])
    gx = int(SG[2])
    gy = int(SG[3])

    b = np.zeros((h,w))

    for j in range(w):
        b[i,j] = int(B[j])

    #print b
    
    flag = np.zeros((h,w))

    if move(sx,sy,b,gx,gy):
        print 'YES'
    else:
        print 'NO'
0