結果

問題 No.124 門松列(3)
ユーザー roiti46roiti46
提出日時 2015-02-24 18:20:09
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 752 bytes
コンパイル時間 428 ms
コンパイル使用メモリ 6,592 KB
実行使用メモリ 6,584 KB
最終ジャッジ日時 2023-09-06 04:06:17
合計ジャッジ時間 2,561 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 17 ms
6,584 KB
testcase_05 AC 17 ms
6,452 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 14 ms
6,296 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 16 ms
6,308 KB
testcase_24 AC 15 ms
6,316 KB
testcase_25 AC 15 ms
6,316 KB
testcase_26 AC 14 ms
6,332 KB
testcase_27 AC 14 ms
6,260 KB
testcase_28 AC 17 ms
6,368 KB
testcase_29 AC 18 ms
6,476 KB
権限があれば一括ダウンロードができます

ソースコード

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)) < 3: 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)]
D = [[10**6]*W for i in xrange(H)]
que = deque([[0,0,0,0,0]])
while que:
    w,h,bw,bh,n = que.popleft()
    if (w,h) == (W-1,H-1):
        print n
        break
    for dx,dy in dxy:
        nw,nh = w+dx,h+dy
        if 0 <= nw < W and 0 <= nh < H:
            if D[nh][nw] < D[h][w]+1: continue
            if not isKadomatsu(M[bh][bw],M[h][w],M[nh][nw]): continue
            que.append([nw,nh,w,h,n+1])
else:
    print -1
0