結果

問題 No.2366 登校
ユーザー logxlogx
提出日時 2021-06-29 21:48:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,104 bytes
コンパイル時間 513 ms
コンパイル使用メモリ 10,732 KB
実行使用メモリ 27,216 KB
最終ジャッジ日時 2023-09-22 17:23:32
合計ジャッジ時間 34,589 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,272 KB
testcase_01 AC 16 ms
8,156 KB
testcase_02 AC 17 ms
8,200 KB
testcase_03 AC 17 ms
8,208 KB
testcase_04 AC 17 ms
8,196 KB
testcase_05 AC 16 ms
8,312 KB
testcase_06 AC 17 ms
8,156 KB
testcase_07 AC 18 ms
8,212 KB
testcase_08 AC 17 ms
8,316 KB
testcase_09 AC 18 ms
8,332 KB
testcase_10 AC 17 ms
8,296 KB
testcase_11 AC 17 ms
8,164 KB
testcase_12 AC 2,148 ms
13,844 KB
testcase_13 AC 2,251 ms
13,992 KB
testcase_14 AC 2,169 ms
14,052 KB
testcase_15 AC 2,183 ms
13,888 KB
testcase_16 AC 2,229 ms
13,916 KB
testcase_17 AC 2,189 ms
13,980 KB
testcase_18 AC 2,215 ms
13,884 KB
testcase_19 AC 2,189 ms
13,956 KB
testcase_20 AC 2,195 ms
13,956 KB
testcase_21 AC 2,192 ms
14,004 KB
testcase_22 AC 1,915 ms
13,120 KB
testcase_23 AC 1,533 ms
27,216 KB
testcase_24 AC 1,559 ms
27,044 KB
testcase_25 TLE -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

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