結果

問題 No.2366 登校
ユーザー shobonvipshobonvip
提出日時 2023-06-30 04:41:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,136 ms / 4,000 ms
コード長 1,039 bytes
コンパイル時間 325 ms
コンパイル使用メモリ 87,252 KB
実行使用メモリ 146,728 KB
最終ジャッジ日時 2023-09-03 02:59:09
合計ジャッジ時間 23,345 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
78,880 KB
testcase_01 AC 78 ms
76,616 KB
testcase_02 AC 110 ms
77,788 KB
testcase_03 AC 195 ms
79,504 KB
testcase_04 AC 76 ms
76,568 KB
testcase_05 AC 127 ms
77,648 KB
testcase_06 AC 178 ms
79,232 KB
testcase_07 AC 194 ms
79,332 KB
testcase_08 AC 216 ms
80,704 KB
testcase_09 AC 213 ms
79,508 KB
testcase_10 AC 115 ms
77,768 KB
testcase_11 AC 142 ms
78,204 KB
testcase_12 AC 1,240 ms
105,024 KB
testcase_13 AC 1,197 ms
105,384 KB
testcase_14 AC 1,217 ms
106,716 KB
testcase_15 AC 1,278 ms
107,488 KB
testcase_16 AC 1,204 ms
105,116 KB
testcase_17 AC 1,231 ms
105,976 KB
testcase_18 AC 1,156 ms
107,248 KB
testcase_19 AC 1,225 ms
105,660 KB
testcase_20 AC 1,203 ms
105,456 KB
testcase_21 AC 1,181 ms
106,428 KB
testcase_22 AC 981 ms
104,632 KB
testcase_23 AC 733 ms
127,452 KB
testcase_24 AC 716 ms
127,700 KB
testcase_25 AC 2,085 ms
146,728 KB
testcase_26 AC 2,136 ms
145,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

n, m, k, t = map(int,input().split())
modoru = [[(-1,-1) for j in range(m)] for i in range(n)]
for i in range(k):
	a, b, c, d = map(int,input().split())
	a -= 1
	b -= 1
	modoru[a][b] = (c, d)

tmax = 601

d = [10 ** 18] * n * m * tmax
d[200] = 0

pq = [(d[200], 200)]

r1 = m * tmax

while pq:
	tmp, nowv = heapq.heappop(pq)
	fnv = nowv
	nowt = nowv % tmax
	nowv //= tmax
	b = nowv % m
	a = nowv // m
	if tmp > d[fnv]: continue
	for xx, yy in [(-1, 0), (1, 0), (0, 1), (0, -1)]:
		x = a + xx
		y = b + yy
		if 0 <= x < n and 0 <= y < m:
			dist = tmp
			targ = x*r1 + y*tmax + min(nowt+1, tmax-1)
			if dist < d[targ]:
				d[targ] = dist
				heapq.heappush(pq, (dist, targ))
	if modoru[a][b][0] == -1: continue
	c, dd = modoru[a][b]
	dist = tmp + dd
	targ = a*r1 + b*tmax + max(0, nowt-c+1)
	if dist < d[targ]:
		d[targ] = dist
		heapq.heappush(pq, (dist, targ))

ans = 10 ** 18
for ts in range(tmax):
	if ts - 200 > t: continue
	ans = min(ans, d[(n-1)*r1 + (m-1)*tmax + ts])

if ans == 10 ** 18:
	print(-1)
else:
	print(ans)
0