結果

問題 No.20 砂漠のオアシス
ユーザー yaoshimaxyaoshimax
提出日時 2015-02-10 23:09:41
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 920 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 6,944 KB
実行使用メモリ 19,360 KB
最終ジャッジ日時 2024-04-21 06:22:36
合計ジャッジ時間 9,606 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
6,656 KB
testcase_01 AC 11 ms
6,400 KB
testcase_02 AC 13 ms
6,656 KB
testcase_03 AC 143 ms
6,784 KB
testcase_04 AC 848 ms
6,912 KB
testcase_05 AC 341 ms
11,136 KB
testcase_06 AC 1,205 ms
12,288 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

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