結果

問題 No.424 立体迷路
ユーザー kitayankitayan
提出日時 2016-10-05 09:38:36
言語 Python2
(2.7.18)
結果
RE  
実行時間 -
コード長 3,133 bytes
コンパイル時間 43 ms
コンパイル使用メモリ 7,168 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-01 12:45:55
合計ジャッジ時間 989 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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
import os

def move(sx,sy,b,gx,gy,flag):
    flag[sx-1,sy-1] = 1
    #print sx,sy,b[sx-1,sy-1]
    #print flag
    if sx+1 <= h and flag[sx,sy-1] == 0:
        if math.fabs(b[sx-1,sy-1]-b[sx,sy-1]) <= 1:
            #print 'x+1'
            if sx+1 == gx and sy == gy:
                return 1
            else:
                if move(sx+1,sy,b,gx,gy,flag):
                    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:
            #print 'x-1'
            if sx-1 == gx and sy == gy:
                return 1
            else:
                if move(sx-1,sy,b,gx,gy,flag):
                    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:
            #print 'y+1'
            if sy+1 == gy and sx == gx:
                return 1
            else:
                if move(sx,sy+1,b,gx,gy,flag):
                    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:
            #print 'y-1'
            if sx == gx and sy-1 == gy:
                return 1
            else:
                if move(sx,sy-1,b,gx,gy,flag):
                    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]:
            #print 'x+2'
            if sx+2 == gx and sy == gy:
                return 1
            else:
                if move(sx+2,sy,b,gx,gy,flag):
                    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]:
            #print 'x-2'
            if sx-2 == gx and sy == gy:
                return 1
            else:
                if move(sx-2,sy,b,gx,gy,flag):
                    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]:
            #print 'y+2'
            if sx == gx and sy+2 == gy:
                return 1
            else:
                if move(sx,sy+2,b,gx,gy,flag):
                    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]:
            #print 'y-2'
            if sx == gx and sy-2 == gy:
                return 1
            else:
                if move(sx,sy-2,b,gx,gy,flag):
                    return 1

    return 0

if __name__ == '__main__':
    h = 5
    w = 5
    sx = 5
    sy = 1
    gx = 4
    gy = 3
    b = [[6,8,2,3,2],[2,4,5,4,3],[0,4,5,2,3],[5,2,6,0,8],[9,8,7,2,8]]
    S  = raw_input().split()
    SG = raw_input().split()
    h = int(S[0])
    w = int(S[1])
    
    b = np.zeros((h,w))

    for i in range(h):
        B = raw_input()
        for j in range(w):
            b[i,j] = int(B[j])
        
    sx = int(SG[0])
    sy = int(SG[1])
    gx = int(SG[2])
    gy = int(SG[3])

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

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