結果

問題 No.20 砂漠のオアシス
ユーザー nagitaosunagitaosu
提出日時 2020-03-13 14:13:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,706 bytes
コンパイル時間 122 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 32,768 KB
最終ジャッジ日時 2024-05-01 19:37:10
合計ジャッジ時間 3,726 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
11,008 KB
testcase_01 AC 29 ms
11,008 KB
testcase_02 AC 29 ms
10,880 KB
testcase_03 AC 44 ms
12,032 KB
testcase_04 AC 44 ms
12,032 KB
testcase_05 AC 321 ms
28,160 KB
testcase_06 AC 367 ms
32,768 KB
testcase_07 AC 360 ms
32,768 KB
testcase_08 AC 362 ms
32,768 KB
testcase_09 AC 348 ms
32,640 KB
testcase_10 WA -
testcase_11 AC 26 ms
11,008 KB
testcase_12 WA -
testcase_13 AC 40 ms
11,904 KB
testcase_14 AC 53 ms
12,672 KB
testcase_15 AC 45 ms
12,288 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 95 ms
15,232 KB
testcase_20 AC 33 ms
11,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import sys
input = sys.stdin.readline
import heapq
INF = 10**9

class Dijkstra:
    def __init__(self, adj):
        self.adj = adj
        self.dist = [INF] * len(adj)
        self.q = []

    def reset(self):
        self.dist = [INF] * len(self.adj)
        self.q = []

    def calc(self, start):
        self.dist[start] = 0
        heapq.heappush(self.q, (0, start))
        while len(self.q) != 0:
            prov_cost, src = heapq.heappop(self.q)
            if self.dist[src] < prov_cost:
                continue
            for dest, cost in self.adj[src]:
                if self.dist[dest] > self.dist[src] + cost:
                    self.dist[dest] = self.dist[src] + cost
                    heapq.heappush(self.q, (self.dist[dest], dest))
        return self.dist

n, v, ox, oy = map(int, input().split())
ox -= 1; oy -= 1
edge = [[] 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:
                continue
            if j + dy < 0 or j + dy >= n:
                continue
            frm = i * n + j 
            too = (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 *= 2
    ret -= dist_from_oasis[n*n - 1]
    ans = max(ans, ret)

if ans > 0:
    print("YES")
else:
    print("NO")
0