結果

問題 No.2695 Warp Zone
コンテスト
ユーザー titia
提出日時 2024-03-22 23:04:05
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 807 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 183 ms
コンパイル使用メモリ 85,132 KB
実行使用メモリ 82,328 KB
最終ジャッジ日時 2026-04-16 15:58:13
合計ジャッジ時間 3,132 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 7 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline

from operator import itemgetter
from heapq import heappop,heappush

H,W,N=map(int,input().split())
WA=[list(map(int,input().split())) for i in range(N)]

WA=[[1,1,1,1]]+WA+[[H,W,H,W]]

DP=[1<<63]*len(WA)
WA.sort(key=itemgetter(0))
WA.sort(key=itemgetter(1))

DP[0]=0

Q=[(0,0)]

while Q:
    time,ind=heappop(Q)

    if DP[ind]!=time:
        continue

    a,b,c,d=WA[ind]
    for j in range(len(WA)):
        e,f,g,h=WA[j]

        if a<=e and b<=f:
            dis=(e-a)+(f-b)

            if DP[j]>DP[ind]+dis:
                DP[j]=DP[ind]+dis
                heappush(Q,(DP[j],j))

        if c<=e and d<=f:
            dis=(e-c)+(f-d)

            if DP[j]>DP[ind]+dis+1:
                DP[j]=DP[ind]+dis+1
                heappush(Q,(DP[j],j))


print(DP[-1])
0