結果

問題 No.124 門松列(3)
ユーザー TawaraTawara
提出日時 2015-12-31 02:00:31
言語 PyPy2
(7.3.15)
結果
TLE  
実行時間 -
コード長 604 bytes
コンパイル時間 484 ms
コンパイル使用メモリ 77,260 KB
実行使用メモリ 284,916 KB
最終ジャッジ日時 2023-10-19 12:48:46
合計ジャッジ時間 13,668 ms
ジャッジサーバーID
(参考情報)
judge14 / 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 #

from collections import defaultdict as D
from heapq import heappop,heappush
I=lambda:map(int,raw_input().split());W,H=I();G=(W-1,H-1)
M=[I()for i in xrange(H)];dxy=((1,0),(0,1),(-1,0),(0,-1))
C=[[D(lambda:W*H+1)for i in xrange(W)]for i in xrange(H)];Q=[]
for x,y in dxy[:2]:A=(M[0][0],M[y][x]);C[y][x][A]=1;Q+=[(1,(x,y),A)]
while Q:
	c,h,A=heappop(Q)
	if h==G:print c;break
	for dx,dy in dxy:
		nx=h[0]+dx;ny=h[1]+dy
		if 0<=nx<W and 0<=ny<H:
			A2=M[ny][nx];nA=(A[1],A2);nc=c+1
			if(A[0]-A[1])*(A[1]-A2)<0 and A[0]!=A2 and nc<C[ny][nx][A]:
				heappush(Q,(nc,(nx,ny),nA));C[ny][nx][nA]=nc
else:print -1
0