結果

問題 No.124 門松列(3)
ユーザー roiti46roiti46
提出日時 2015-02-24 18:32:22
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 921 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 6,676 KB
実行使用メモリ 72,648 KB
最終ジャッジ日時 2023-09-06 04:11:58
合計ジャッジ時間 12,952 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import sys
from collections import deque
sys.setrecursionlimit(100000)
dxy = zip([1,0,-1,0],[0,1,0,-1])
def isKadomatsu(*A):
    if len(set(A)) < len(A): return False
    med = sorted(A)[1]
    return True if A.index(med) != 1 else False
    
W,H = map(int,raw_input().split())
M = [map(int,raw_input().split()) for i in xrange(H)]
que = deque([[1,0,M[0][0],1], [0,1,M[0][0],1]])
cost = [[[[-1]*W for i in xrange(H)] for j in xrange(10)] for k in xrange(10)]
cost[0][M[0][0]][1][0] = cost[0][M[0][0]][0][1] = 1

while que:
    w,h,b,d = que.popleft()
    if (w,h) == (W-1,H-1):
        print d
        break
    cost[b][M[h][w]][h][w] = d
    for dx,dy in dxy:
        nw,nh = w+dx,h+dy
        if not (0 <= nw < W and 0 <= nh < H): continue
        if not isKadomatsu(b, M[h][w], M[nh][nw]): continue
        if cost[M[h][w]][M[nh][nw]][nh][nw] != -1: continue
        que.append([nw,nh,M[h][w],d+1])
else:
    print -1
0