結果
問題 | No.20 砂漠のオアシス |
ユーザー |
|
提出日時 | 2018-07-29 13:21:25 |
言語 | Python2 (2.7.18) |
結果 |
AC
|
実行時間 | 222 ms / 5,000 ms |
コード長 | 1,000 bytes |
コンパイル時間 | 662 ms |
コンパイル使用メモリ | 7,040 KB |
実行使用メモリ | 9,216 KB |
最終ジャッジ日時 | 2024-07-16 03:19:34 |
合計ジャッジ時間 | 2,572 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#yuki20 import heapq,sys direction=[(1,0),(0,1),(-1,0),(0,-1)] def dijkstra(sx,sy,L): N=len(L) dist=[[float("inf")] * N for i in xrange(N)] dist[sy][sx]= 0 queue=[(0,sx,sy)] while queue: d,x,y = heapq.heappop(queue) if dist[y][x]<d: continue for dx, dy in direction: nx=x+dx ny=y+dy if 0<=nx<N and 0<=ny<N and dist[ny][nx]>d+L[ny][nx]: dist[ny][nx]=d+L[ny][nx] heapq.heappush(queue,(dist[ny][nx], nx, ny)) return dist n,v,xx,yy=map(int,raw_input().split()) l=[map(int,raw_input().split()) for i in xrange(n)] xx-=1 yy-=1 dist=dijkstra(0,0,l) if dist[n-1][n-1]<v: print 'YES' sys.exit() if xx>=0 and dist[yy][xx]<v: v=(v-dist[yy][xx])*2 dist=dijkstra(xx,yy,l) if dist[n-1][n-1]<v: print 'YES' sys.exit() print 'NO'