結果

問題 No.34 砂漠の行商人
ユーザー TawaraTawara
提出日時 2015-12-30 00:15:09
言語 Python2
(2.7.18)
結果
AC  
実行時間 153 ms / 5,000 ms
コード長 590 bytes
コンパイル時間 546 ms
コンパイル使用メモリ 6,512 KB
実行使用メモリ 7,160 KB
最終ジャッジ日時 2023-09-10 19:19:29
合計ジャッジ時間 2,989 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
6,644 KB
testcase_01 AC 13 ms
6,500 KB
testcase_02 AC 16 ms
6,480 KB
testcase_03 AC 14 ms
6,716 KB
testcase_04 AC 33 ms
6,532 KB
testcase_05 AC 38 ms
6,584 KB
testcase_06 AC 28 ms
6,548 KB
testcase_07 AC 70 ms
6,720 KB
testcase_08 AC 80 ms
6,860 KB
testcase_09 AC 62 ms
6,788 KB
testcase_10 AC 33 ms
6,828 KB
testcase_11 AC 49 ms
7,092 KB
testcase_12 AC 21 ms
6,572 KB
testcase_13 AC 152 ms
7,016 KB
testcase_14 AC 153 ms
7,160 KB
testcase_15 AC 16 ms
6,572 KB
testcase_16 AC 29 ms
6,804 KB
testcase_17 AC 16 ms
6,580 KB
testcase_18 AC 16 ms
6,532 KB
testcase_19 AC 72 ms
6,928 KB
testcase_20 AC 106 ms
7,112 KB
testcase_21 AC 19 ms
6,696 KB
testcase_22 AC 21 ms
6,712 KB
testcase_23 AC 16 ms
6,600 KB
testcase_24 AC 119 ms
7,096 KB
testcase_25 AC 29 ms
6,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from Queue import deque
N,V,Sx,Sy,Gx,Gy = map(int,raw_input().split())
Sx -= 1; Sy -= 1; Gx -= 1; Gy -= 1
L = [map(int,raw_input().split()) for i in xrange(N)]
dxy = ((1,0),(0,1),(-1,0),(0,-1))
Q = deque([(Sx,Sy,V,0)])
visited = [[0]*N for i in xrange(N)]
visited[Sy][Sx] = V
while Q:
	hx,hy,v,c = Q.popleft()
	if (hx,hy) == (Gx,Gy): print c; break
	if v < visited[hy][hx]: continue
	for dx,dy in dxy:
		nx = hx + dx; ny = hy + dy
		if 0 <= nx < N and 0 <= ny < N and v - L[ny][nx] > visited[ny][nx]:
			visited[ny][nx] = v - L[ny][nx]
			Q.append((nx,ny,v - L[ny][nx],c+1))
else:
	print -1
0