結果

問題 No.2366 登校
ユーザー shobonvipshobonvip
提出日時 2023-06-30 04:42:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,587 ms / 4,000 ms
コード長 1,039 bytes
コンパイル時間 810 ms
コンパイル使用メモリ 86,876 KB
実行使用メモリ 111,752 KB
最終ジャッジ日時 2023-09-03 02:59:18
合計ジャッジ時間 17,540 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
77,672 KB
testcase_01 AC 77 ms
71,528 KB
testcase_02 AC 91 ms
76,152 KB
testcase_03 AC 173 ms
78,564 KB
testcase_04 AC 75 ms
71,248 KB
testcase_05 AC 118 ms
77,448 KB
testcase_06 AC 172 ms
78,496 KB
testcase_07 AC 182 ms
78,712 KB
testcase_08 AC 208 ms
79,204 KB
testcase_09 AC 202 ms
79,448 KB
testcase_10 AC 97 ms
76,264 KB
testcase_11 AC 128 ms
77,516 KB
testcase_12 AC 919 ms
92,020 KB
testcase_13 AC 924 ms
92,876 KB
testcase_14 AC 940 ms
92,732 KB
testcase_15 AC 962 ms
92,728 KB
testcase_16 AC 985 ms
92,120 KB
testcase_17 AC 1,000 ms
93,308 KB
testcase_18 AC 1,000 ms
92,304 KB
testcase_19 AC 988 ms
93,268 KB
testcase_20 AC 1,001 ms
92,916 KB
testcase_21 AC 958 ms
92,036 KB
testcase_22 AC 739 ms
91,396 KB
testcase_23 AC 393 ms
101,536 KB
testcase_24 AC 394 ms
101,460 KB
testcase_25 AC 1,587 ms
111,752 KB
testcase_26 AC 1,565 ms
110,068 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 = 401

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