結果

問題 No.424 立体迷路
ユーザー kitayankitayan
提出日時 2016-10-04 16:53:19
言語 Python2
(2.7.18)
結果
RE  
実行時間 -
コード長 2,685 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2024-05-01 11:37:07
合計ジャッジ時間 1,594 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
権限があれば一括ダウンロードができます

ソースコード

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()
    h = int(S[0])
    w = int(S[1])
    
    SG = raw_input().split()
    sx = int(SG[0])
    sy = int(SG[1])
    gx = int(SG[2])
    gy = int(SG[3])

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

    for i in range(h):
        B = raw_input()
        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