結果
| 問題 |
No.2366 登校
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-30 23:20:29 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,515 bytes |
| コンパイル時間 | 236 ms |
| コンパイル使用メモリ | 82,792 KB |
| 実行使用メモリ | 254,336 KB |
| 最終ジャッジ日時 | 2024-07-07 22:05:38 |
| 合計ジャッジ時間 | 39,383 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 21 WA * 2 TLE * 1 -- * 1 |
ソースコード
import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd
n,m,k,t = map(int,input().split())
t = min(t, 330)
wonderc = defaultdict()
wonderd = defaultdict()
for i in range(k):
a,b,c,d = map(int,input().split())
wonderc[(a,b)] = c
wonderd[(a,b)] = d
#ダイクストラ法
def dijkstra(s): # sがスタート、nが頂点数
INF = 10**15
dist = [[INF]*(510) for i in range(n*m)]
que = [(0,s,170)]
dist[s][170] = 0
while que:
c,crr,tt = heappop(que)
x,y = crr//m, crr%m
# print(x,y,tt)
if c > dist[crr][tt]: continue
if (x,y) in wonderc.keys():
if dist[crr][max(0, tt-wonderc[(x,y)]+1)] > dist[crr][tt]+wonderd[(x,y)]:
dist[crr][max(0, tt-wonderc[(x,y)]+1)] = dist[crr][tt]+wonderd[(x,y)]
heappush(que,(dist[crr][max(0, tt-wonderc[(x,y)]+1)],crr, max(0, tt-wonderc[(x,y)]+1)))
for dx,dy in [[0,1],[0,-1],[1,0],[-1,0]]:
nx,ny = x+dx,y+dy
if not(0<=nx<n and 0<= ny<m): continue
nxt = nx*m + ny
if dist[crr][tt] < dist[nxt][min(510-1,tt+1)]:
dist[nxt][min(510-1,tt+1)] = dist[crr][tt]
heappush(que,(dist[nxt][min(510-1,tt+1)],nxt,min(510-1,tt+1)))
return dist
d =dijkstra(0)
ans = min(d[-1][:t+170+1])
print(ans) if ans != 10**15 else print(-1)