結果

問題 No.2695 Warp Zone
ユーザー sasa8uyauyasasa8uyauya
提出日時 2024-03-23 04:36:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 532 bytes
コンパイル時間 392 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 108,516 KB
最終ジャッジ日時 2024-03-23 04:36:23
合計ジャッジ時間 5,073 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,460 KB
testcase_01 AC 39 ms
53,460 KB
testcase_02 AC 39 ms
53,460 KB
testcase_03 AC 229 ms
108,516 KB
testcase_04 AC 207 ms
107,236 KB
testcase_05 AC 215 ms
107,228 KB
testcase_06 AC 223 ms
108,380 KB
testcase_07 AC 214 ms
108,380 KB
testcase_08 AC 56 ms
64,316 KB
testcase_09 AC 158 ms
87,000 KB
testcase_10 AC 40 ms
53,460 KB
testcase_11 AC 110 ms
79,448 KB
testcase_12 AC 166 ms
91,224 KB
testcase_13 AC 38 ms
53,460 KB
testcase_14 AC 177 ms
95,952 KB
testcase_15 AC 166 ms
85,720 KB
testcase_16 AC 99 ms
78,564 KB
testcase_17 AC 120 ms
81,752 KB
testcase_18 AC 200 ms
101,084 KB
testcase_19 AC 52 ms
64,320 KB
testcase_20 AC 181 ms
98,404 KB
testcase_21 AC 176 ms
95,448 KB
testcase_22 AC 129 ms
84,312 KB
testcase_23 AC 191 ms
91,736 KB
testcase_24 AC 38 ms
53,460 KB
testcase_25 AC 39 ms
53,460 KB
testcase_26 AC 38 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h,w,n=map(int,input().split())
o=[tuple(map(int,input().split())) for i in range(n)]
e=[[] for i in range(n+2)]
for i in range(n):
	a,b,c,d=o[i]
	e[n]+=[(i,abs(a-1)+abs(b-1))]
	e[i]+=[(n+1,1+abs(h-c)+abs(w-d))]
	for j in range(n):
		if i!=j:
			a2,b2,c2,d2=o[j]
			e[i]+=[(j,1+abs(c-a2)+abs(d-b2))]
v=[h+w-2]*(n+2)
v[n]=0
q=[]
from heapq import heappush,heappop
heappush(q,(0,n))
while len(q)>0:
	sc,sp=heappop(q)
	if sc>v[sp]:
		continue
	for tp,tc in e[sp]:
		if v[tp]>sc+tc:
			v[tp]=sc+tc
			heappush(q,(v[tp],tp))
print(v[n+1])
0