結果

問題 No.124 門松列(3)
コンテスト
ユーザー roiti46
提出日時 2015-02-24 18:21:23
言語 PyPy2
(7.3.15)
結果
WA  
実行時間 -
コード長 670 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 282 ms
コンパイル使用メモリ 77,240 KB
最終ジャッジ日時 2025-12-03 14:13:31
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 3
other AC * 9 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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