結果
問題 | No.20 砂漠のオアシス |
ユーザー | nagitaosu |
提出日時 | 2020-03-13 14:43:24 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 407 ms / 5,000 ms |
コード長 | 1,706 bytes |
コンパイル時間 | 320 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 32,896 KB |
最終ジャッジ日時 | 2024-11-22 02:54:02 |
合計ジャッジ時間 | 4,026 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#!/usr/bin/env python3import sysinput = sys.stdin.readlineimport heapqINF = 10**9class Dijkstra:def __init__(self, adj):self.adj = adjself.dist = [INF] * len(adj)self.q = []def reset(self):self.dist = [INF] * len(self.adj)self.q = []def calc(self, start):self.dist[start] = 0heapq.heappush(self.q, (0, start))while len(self.q) != 0:prov_cost, src = heapq.heappop(self.q)if self.dist[src] < prov_cost:continuefor dest, cost in self.adj[src]:if self.dist[dest] > self.dist[src] + cost:self.dist[dest] = self.dist[src] + costheapq.heappush(self.q, (self.dist[dest], dest))return self.distn, v, oy, ox = map(int, input().split())ox -= 1; oy -= 1edge = [[] for _ in range(n * n)]field = []for _ in range(n):field.append([int(item) for item in input().split()])delta = [(0, 1), (1, 0), (0, -1), (-1, 0)]for i in range(n):for j in range(n):for dx, dy in delta:if i + dx < 0 or i + dx >= n:continueif j + dy < 0 or j + dy >= n:continuefrm = i * n + jtoo = (i + dx) * n + (j + dy)edge[frm].append((too, field[i + dx][j + dy]))DIJK = Dijkstra(edge)dist_from_start = DIJK.calc(0)ans = v - dist_from_start[n*n-1]if ox != -1 and oy != -1:DIJK.reset()dist_from_oasis = DIJK.calc(ox*n + oy)ret = v - dist_from_start[ox * n + oy]ret *= 2ret -= dist_from_oasis[n*n - 1]ans = max(ans, ret)if ans > 0:print("YES")else:print("NO")