結果

問題 No.124 門松列(3)
ユーザー TawaraTawara
提出日時 2015-12-31 02:47:25
言語 Python2
(2.7.18)
結果
AC  
実行時間 45 ms / 5,000 ms
コード長 485 bytes
コンパイル時間 631 ms
コンパイル使用メモリ 7,140 KB
実行使用メモリ 8,748 KB
最終ジャッジ日時 2023-10-19 12:49:38
合計ジャッジ時間 1,650 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
8,748 KB
testcase_01 AC 12 ms
6,680 KB
testcase_02 AC 12 ms
6,680 KB
testcase_03 AC 45 ms
8,748 KB
testcase_04 AC 23 ms
8,748 KB
testcase_05 AC 24 ms
8,748 KB
testcase_06 AC 12 ms
6,680 KB
testcase_07 AC 12 ms
6,680 KB
testcase_08 AC 12 ms
6,680 KB
testcase_09 AC 11 ms
6,680 KB
testcase_10 AC 11 ms
6,680 KB
testcase_11 AC 12 ms
6,680 KB
testcase_12 AC 12 ms
6,680 KB
testcase_13 AC 14 ms
6,680 KB
testcase_14 AC 13 ms
6,692 KB
testcase_15 AC 13 ms
6,692 KB
testcase_16 AC 14 ms
6,820 KB
testcase_17 AC 12 ms
6,716 KB
testcase_18 AC 14 ms
6,696 KB
testcase_19 AC 12 ms
6,712 KB
testcase_20 AC 13 ms
6,760 KB
testcase_21 AC 11 ms
6,696 KB
testcase_22 AC 13 ms
6,740 KB
testcase_23 AC 16 ms
7,456 KB
testcase_24 AC 20 ms
7,692 KB
testcase_25 AC 19 ms
7,692 KB
testcase_26 AC 13 ms
6,964 KB
testcase_27 AC 15 ms
6,900 KB
testcase_28 AC 23 ms
8,748 KB
testcase_29 AC 24 ms
8,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop,heappush
I=lambda:map(int,raw_input().split());W,H=I()
M=[I()for i in range(H)];D=((1,0),(0,1),(-1,0),(0,-1))
C=[[10*[W*H]for i in range(W)]for i in range(H)];Q=[]
for x,y in D[:2]:m=M[0][0];C[y][x][m]=1;Q+=[(1,x,y,m)]
while Q:
	c,x,y,b=heappop(Q)
	if(W-x)*(H-y)==1:print c;break
	t=M[y][x];d=c+1
	for u,v in D:
		z=x+u;w=y+v
		if 0<=z<W and 0<=w<H:
			n=M[w][z]
			if(n-t)*(t-b)<0 and b^n and d<C[w][z][t]:
				heappush(Q,(d,z,w,t));C[w][z][t]=d
else:print-1
0