結果
| 問題 | No.20 砂漠のオアシス | 
| コンテスト | |
| ユーザー |  mkawa2 | 
| 提出日時 | 2020-01-03 22:40:22 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,593 bytes | 
| コンパイル時間 | 89 ms | 
| コンパイル使用メモリ | 12,928 KB | 
| 実行使用メモリ | 15,232 KB | 
| 最終ジャッジ日時 | 2024-11-22 19:38:17 | 
| 合計ジャッジ時間 | 3,010 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 19 WA * 2 | 
ソースコード
from heapq import *
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def main():
    n, v, oj, oi = MI()
    oi, oj = oi - 1, oj - 1
    ll = [LI() for _ in range(n)]
    dp0 = [[0] * n for _ in range(n)]
    hp=[]
    heappush(hp,[-v,0,0])
    while hp:
        p,i,j=heappop(hp)
        p=-p
        if p<=dp0[i][j]:continue
        dp0[i][j]=p
        if (i,j)==(oi,oj):continue
        for di,dj in [(1,0),(0,1),(-1,0),(0,-1)]:
            ni,nj=i+di,j+dj
            if ni<0 or ni>=n or nj<0 or nj>=n:continue
            np=p-ll[ni][nj]
            if np<dp0[ni][nj]:continue
            if (ni,nj)==(n-1,n-1):
                print("YES")
                exit()
            heappush(hp,[-np,ni,nj])
    if dp0[oi][oj]==0:
        print("NO")
        exit()
    dp1 = [[0] * n for _ in range(n)]
    hp=[]
    heappush(hp,[-dp0[oi][oj]*2,oi,oj])
    while hp:
        p,i,j=heappop(hp)
        p=-p
        if p<=dp1[i][j]:continue
        dp1[i][j]=p
        for di,dj in [(1,0),(0,1),(-1,0),(0,-1)]:
            ni,nj=i+di,j+dj
            if ni<0 or ni>=n or nj<0 or nj>=n:continue
            np=p-ll[ni][nj]
            if np<dp1[ni][nj]:continue
            if (ni,nj)==(n-1,n-1):
                print("YES")
                exit()
            heappush(hp,[-np,ni,nj])
    print("NO")
main()
            
            
            
        