結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
8,760 KB
testcase_01 AC 13 ms
6,696 KB
testcase_02 AC 13 ms
6,696 KB
testcase_03 AC 49 ms
8,760 KB
testcase_04 AC 25 ms
8,760 KB
testcase_05 AC 24 ms
8,760 KB
testcase_06 AC 13 ms
6,696 KB
testcase_07 AC 14 ms
6,696 KB
testcase_08 AC 13 ms
6,696 KB
testcase_09 AC 14 ms
6,696 KB
testcase_10 AC 14 ms
6,696 KB
testcase_11 AC 13 ms
6,696 KB
testcase_12 AC 12 ms
6,696 KB
testcase_13 AC 13 ms
6,696 KB
testcase_14 AC 13 ms
6,708 KB
testcase_15 AC 13 ms
6,708 KB
testcase_16 AC 16 ms
6,836 KB
testcase_17 AC 13 ms
6,732 KB
testcase_18 AC 13 ms
6,708 KB
testcase_19 AC 13 ms
6,732 KB
testcase_20 AC 14 ms
6,776 KB
testcase_21 AC 13 ms
6,708 KB
testcase_22 AC 13 ms
6,756 KB
testcase_23 AC 17 ms
7,472 KB
testcase_24 AC 20 ms
7,704 KB
testcase_25 AC 19 ms
7,704 KB
testcase_26 AC 15 ms
6,980 KB
testcase_27 AC 14 ms
6,912 KB
testcase_28 AC 25 ms
8,760 KB
testcase_29 AC 26 ms
8,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 range(H)];dxy=((1,0),(0,1),(-1,0),(0,-1))
C=[[[W*H+1]*10 for i in range(W)]for i in range(H)];Q=[]
for x,y in dxy[:2]:C[y][x][M[0][0]]=1;Q+=[(1,(x,y),M[0][0])]
while Q:
	c,h,b=heappop(Q)
	if h==G:print c;break
	t=M[h[1]][h[0]];nc=c+1
	for dx,dy in dxy:
		nx=h[0]+dx;ny=h[1]+dy
		if 0<=nx<W and 0<=ny<H:
			n=M[ny][nx]
			if(n-t)*(t-b)<0 and b!=n and nc<C[ny][nx][t]:
				heappush(Q,(nc,(nx,ny),t));C[ny][nx][t]=nc
else:
	print -1
0