結果

問題 No.2366 登校
ユーザー logxlogx
提出日時 2021-06-29 21:29:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,245 ms / 4,000 ms
コード長 1,104 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 87,064 KB
実行使用メモリ 130,100 KB
最終ジャッジ日時 2023-09-03 02:47:22
合計ジャッジ時間 23,779 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,120 KB
testcase_01 AC 68 ms
71,460 KB
testcase_02 AC 68 ms
71,332 KB
testcase_03 AC 69 ms
71,520 KB
testcase_04 AC 69 ms
71,244 KB
testcase_05 AC 71 ms
71,356 KB
testcase_06 AC 70 ms
71,360 KB
testcase_07 AC 71 ms
71,268 KB
testcase_08 AC 70 ms
71,620 KB
testcase_09 AC 71 ms
71,360 KB
testcase_10 AC 70 ms
71,380 KB
testcase_11 AC 69 ms
71,336 KB
testcase_12 AC 1,186 ms
89,828 KB
testcase_13 AC 1,100 ms
88,996 KB
testcase_14 AC 1,184 ms
88,832 KB
testcase_15 AC 1,139 ms
89,784 KB
testcase_16 AC 1,126 ms
88,384 KB
testcase_17 AC 1,143 ms
89,608 KB
testcase_18 AC 1,137 ms
90,384 KB
testcase_19 AC 1,150 ms
89,796 KB
testcase_20 AC 1,161 ms
89,540 KB
testcase_21 AC 1,139 ms
88,212 KB
testcase_22 AC 863 ms
88,908 KB
testcase_23 AC 597 ms
101,864 KB
testcase_24 AC 591 ms
101,744 KB
testcase_25 AC 3,245 ms
130,100 KB
testcase_26 AC 3,217 ms
126,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

def chmin(a,b):
    if a>b:
        return True
    return False

N,M,K,T=map(int,input().split())
C=[[0]*M for i in range(N)]
D=[[0]*M for i in range(N)]

def valid(i,j):
    return 0<=i and i<N and 0<=j and j<M

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

INF=10**15
dp=[[[INF]*M for i in range(N)] for j in range(2*(N+M)+1)]
dp[0+N+M][0][0]=0

q=[(0,0+N+M,0,0)]
dxy=[(0,1),(1,0),(0,-1),(-1,0)]

while len(q):
    tir,time,a,b=heapq.heappop(q)
    if dp[time][a][b] < tir:
        continue
    for dx,dy in dxy:
        na,nb = a+dx, b+dy
        if valid(na,nb) and time<2*(N+M) and dp[time+1][na][nb] > tir:
            dp[time+1][na][nb]=dp[time][a][b]
            heapq.heappush(q,(tir,time+1,na,nb))
    
    if C[a][b]>0 and D[a][b]>0:
        ntime=max(0,time-C[a][b]+1)
        if dp[ntime][a][b] > tir+D[a][b]:
            dp[ntime][a][b]=tir+D[a][b]
            heapq.heappush(q,(dp[ntime][a][b],ntime,a,b))

ans=INF

for i in range(-(N+M),min(T+1,N+M+1)):
    ans=min(ans,dp[i+N+M][N-1][M-1])

if ans==INF:
    ans=-1
print(ans)
0