結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 17 ms
6,460 KB
testcase_05 AC 16 ms
6,404 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 13 ms
6,284 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 14 ms
6,312 KB
testcase_24 AC 15 ms
6,224 KB
testcase_25 AC 15 ms
6,412 KB
testcase_26 AC 13 ms
6,196 KB
testcase_27 AC 14 ms
6,396 KB
testcase_28 AC 17 ms
6,444 KB
testcase_29 AC 17 ms
6,456 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)]
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 not isKadomatsu(M[bh][bw],M[h][w],M[nh][nw]): continue
            que.append([nw,nh,w,h,n+1])
else:
    print -1
0