結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 2020-03-20 02:59:43 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 197 ms / 5,000 ms |
| コード長 | 1,321 bytes |
| コンパイル時間 | 104 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 21,616 KB |
| 最終ジャッジ日時 | 2024-12-14 03:51:29 |
| 合計ジャッジ時間 | 2,658 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#!/usr/bin/ python3.8
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from heapq import heappop, heappush
N, V, Oy, Ox = map(int, readline().split())
Ox -= 1
Oy -= 1
oasis = Ox * N + Oy
start = 0
goal = N * N - 1
L = tuple(map(int, read().split()))
graph = [[] for _ in range(N * N)]
for i in range(N * N):
x, y = divmod(i, N)
if x:
j = i - N
graph[i].append(j)
graph[j].append(i)
if y:
j = i - 1
graph[i].append(j)
graph[j].append(i)
def dijkstra(start):
INF = 10 ** 9
dist = [INF] * (N * N)
dist[start] = 0
q = [start]
mask = (1 << 20) - 1
while q:
x = heappop(q)
dv = x >> 20
v = x & mask
if dist[v] < dv:
continue
for w in graph[v]:
dw = dv + L[w]
if dist[w] <= dw:
continue
dist[w] = dw
heappush(q, (dw << 20) + w)
return dist
def solve():
global V
dist1 = dijkstra(start)
if dist1[goal] < V:
return True
if Ox == -1:
return False
dist2 = dijkstra(oasis)
V -= dist1[oasis]
if V <= 0:
return False
V *= 2
V -= dist2[goal]
return V > 0
print('YES' if solve() else 'NO')
maspy