結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
6,816 KB
testcase_01 AC 12 ms
6,940 KB
testcase_02 AC 15 ms
6,940 KB
testcase_03 AC 146 ms
6,940 KB
testcase_04 AC 813 ms
6,940 KB
testcase_05 AC 326 ms
11,008 KB
testcase_06 AC 1,217 ms
12,416 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]:
               heappush(pq,(npower,nx,ny,nused))
print "NO"


0