結果

問題 No.2366 登校
ユーザー titia
提出日時 2023-07-01 02:22:06
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 987 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 82,116 KB
実行使用メモリ 120,232 KB
最終ジャッジ日時 2024-07-08 09:01:20
合計ジャッジ時間 39,361 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 23 TLE * 1 -- * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from heapq import heappop,heappush

N,M,K,T=map(int,input().split())

X=[[(-1,-1)]*M for i in range(N)]

for i in range(K):
    a,b,c,d=map(int,input().split())
    a-=1
    b-=1
    X[a][b]=[c,d]

DP=[[[1<<63]*M for i in range(N)] for j in range(400)]

Q=[(0,0,0,0)]
DP[200][0][0]=0

while Q:
    now,x,y,time=heappop(Q)
    if DP[time+200][x][y]!=now:
        continue

    for z,w in [(x,y+1),(x,y-1),(x+1,y),(x-1,y)]:
        if 0<=z<N and 0<=w<M and 0<=time+1+200<400 and DP[time+1+200][z][w]>now:
            DP[time+1+200][z][w]=now
            heappush(Q,(DP[time+1+200][z][w],z,w,time+1))

    if X[x][y]!=(-1,-1):
        c,d=X[x][y]
        if 0<=time-c+1+200<400 and DP[time-c+1+200][x][y]>now+d:
            DP[time-c+1+200][x][y]=now+d
            heappush(Q,(DP[time-c+1+200][x][y],x,y,time-c+1))

ANS=1<<63

for i in range(400):
    if i-200<=T:
        ANS=min(ANS,DP[i][N-1][M-1])

if ANS>=1<<60:
    print(-1)
else:
    print(ANS)
0