結果

問題 No.20 砂漠のオアシス
ユーザー yaoshimax
提出日時 2015-02-10 23:09:41
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 920 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 17,664 KB
最終ジャッジ日時 2024-10-13 05:02:16
合計ジャッジ時間 9,175 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7 TLE * 1 -- * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop
N,V,Ox,Oy=map(int,raw_input().split())
L=[[0 for i in range(N)] for j in range(N)]
for i in range(N):
   L[i] = map(int,raw_input().split())

P=[[[-1 for k in range(2)] for i in range(N)] for j in range(N)]
pq=[]
heappush(pq,(V,0,0,0))
d1 = [1,0,-1,0]
d2 = [0,1,0,-1]
while len(pq) != 0:
   power,x,y,used = heappop(pq)
   if power < P[x][y][used]:
      continue
   P[x][y][used]=power
   if (x,y)==(N-1,N-1):
      print "YES"
      exit()
   for dx,dy in zip(d1,d2):
      nx = x+dx
      ny = y+dy;
      if nx>=0 and ny >= 0 and nx <N and ny <N:
         if power-L[nx][ny]>0:
            npower=power-L[nx][ny]
            nused = used
            if (nx+1,ny+1)==(Ox,Oy) and used==0:
               npower*=2
               nused = 1
            if npower > P[nx][ny][nused]:
               P[nx][ny][nused]=npower
               heappush(pq,(npower,nx,ny,nused))
print "NO"


0