結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
ゆるく
|
| 提出日時 | 2015-05-01 05:03:27 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 189 ms / 5,000 ms |
| コード長 | 1,512 bytes |
| コンパイル時間 | 141 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 12,928 KB |
| 最終ジャッジ日時 | 2024-10-13 05:09:06 |
| 合計ジャッジ時間 | 2,483 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
import heapq
#import re
#import bisect
#from collections import deque
n, v, ox, oy = (int(i) for i in input().split())
l = [[int(i) for i in input().split()] for i in range(n)]
cost = [[0xFFFFFFFF for i in range(n)] for j in range(n)]
direction = ((1, 0), (0, 1), (-1, 0), (0, -1))
def solve(x, y):
h = []
heapq.heappush(h, (0 << 24) + (x << 8) + y)
visit = [[False for i in range(n)] for j in range(n)]
for i in range(n):
for j in range(n):
cost[i][j] = 0xFFFFFFFF
cost[y][x] = 0
visit[y][x] = True
while (h):
vh = heapq.heappop(h)
vx = (vh >> 8) & 0x00FF
vy = vh & 0x00FF
nowcost = cost[vy][vx]
visit[vy][vx] = True
for i in range(4):
mx = vx + direction[i][0]
my = vy + direction[i][1]
if(mx < 0 or my < 0 or mx >= n or my >= n):
continue
newcost = nowcost + l[my][mx]
if cost[my][mx] > newcost:
cost[my][mx] = newcost
if visit[my][mx] == False:
heapq.heappush(h, (newcost << 24) + (mx << 8) + my)
solve(0, 0)
if cost[n - 1][n - 1] < v:
print("YES")
else:
if (ox > 0 and oy > 0):
os = cost[oy - 1][ox - 1]
if os < v:
solve(ox - 1, oy - 1)
if cost[n - 1][n - 1] < (v - os) * 2:
print("YES")
else:
print("NO")
else:
print("NO")
else:
print("NO")
ゆるく