結果

問題 No.2366 登校
ユーザー shobonvipshobonvip
提出日時 2023-06-30 04:35:12
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,572 bytes
コンパイル時間 505 ms
コンパイル使用メモリ 86,936 KB
実行使用メモリ 83,320 KB
最終ジャッジ日時 2023-09-22 05:10:50
合計ジャッジ時間 11,195 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 223 ms
78,432 KB
testcase_01 AC 89 ms
76,296 KB
testcase_02 AC 122 ms
77,564 KB
testcase_03 AC 321 ms
78,956 KB
testcase_04 AC 88 ms
76,316 KB
testcase_05 AC 182 ms
77,996 KB
testcase_06 AC 263 ms
79,080 KB
testcase_07 AC 541 ms
80,760 KB
testcase_08 AC 1,810 ms
83,320 KB
testcase_09 AC 631 ms
80,020 KB
testcase_10 AC 135 ms
77,568 KB
testcase_11 AC 177 ms
78,548 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# これ解くのに 998244353 時間かかった!
# ぼくが弱いだけで, ★3.0 …かも?

# よく考えると T が大きければ何もする必要はないし, 時を戻すときも N+M-1 以上時を戻す必要もない.
# そう思うと, 時間の初期値を 200 として, 時間を 600 までもつ.
# -> 時間は 0 より戻れないし, 600 より進めない. でもそれでいい.
# その間で, (時間, 位置) の拡張 dijkstra 法を行うとよい.
# O((N+M)NM log(NM)) になる.


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
	tmp = -tmp
	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