結果
問題 |
No.124 門松列(3)
|
ユーザー |
|
提出日時 | 2015-02-24 18:24:51 |
言語 | Python2 (2.7.18) |
結果 |
TLE
|
実行時間 | - |
コード長 | 850 bytes |
コンパイル時間 | 160 ms |
コンパイル使用メモリ | 7,040 KB |
実行使用メモリ | 65,344 KB |
最終ジャッジ日時 | 2024-06-23 22:58:21 |
合計ジャッジ時間 | 12,740 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 4 |
other | TLE * 1 -- * 25 |
ソースコード
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,0,0,1], [0,1,0,0,1]]) D = [[10**6]*W for i in xrange(H)] D[0][0] = 0 D[1][0] = D[0][1] = 1 while que: w,h,bw,bh,d = que.popleft() if (w,h) == (W-1,H-1): print d 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 D[nh][nw] = min(D[nh][nw],d+1) que.append([nw,nh,w,h,d+1]) else: print -1