結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
yaoshimax
|
| 提出日時 | 2015-02-10 23:04:28 |
| 言語 | Python2 (2.7.18) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 881 bytes |
| コンパイル時間 | 836 ms |
| コンパイル使用メモリ | 7,040 KB |
| 実行使用メモリ | 19,104 KB |
| 最終ジャッジ日時 | 2024-10-13 05:02:06 |
| 合計ジャッジ時間 | 9,802 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 7 TLE * 1 -- * 13 |
ソースコード
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"
yaoshimax