結果

問題 No.1638 Robot Maze
ユーザー tcltk
提出日時 2021-10-17 06:13:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,245 bytes
コンパイル時間 694 ms
コンパイル使用メモリ 82,056 KB
実行使用メモリ 90,472 KB
最終ジャッジ日時 2024-09-17 19:37:33
合計ジャッジ時間 10,310 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35 WA * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


# sys.setrecursionlimit(1000000)

# _INPUT = """2 2
# 0 0 0 0 1 1
# 1 1 2 2
# .@
# #.
# """
# sys.stdin = io.StringIO(_INPUT)

INF = 10**20

YES = 'Yes'
NO = 'No'

def solve():
    dist = [[INF] * W for _ in range(H)]

    hq = []
    dist[StartY][StartX] = 0
    heapq.heappush(hq, (0, StartX, StartY))
    while hq:
        d, x, y = heapq.heappop(hq)
        if (x, y) == (GoalX, GoalY):
            return d
        for x1, y1, d1 in [(x-1, y, d+L), (x+1, y, d+R), (x, y-1, U), (x, y+1, D)]:
            if not(0 <= x1 < W and 0 <= y1 < H) or C[y1][x1] == '#':
                continue
            elif C[y1][x1] == '@':
                d1 += P
            if d1 < dist[y1][x1]:
                dist[y1][x1] = d1
                heapq.heappush(hq, (d1, x1, y1))
    return INF

H, W = map(int, input().split())
U, D, R, L, K, P = map(int, input().split())
StartX, StartY, GoalX, GoalY = map(lambda x: int(x)-1, input().split())
C = [input() for _ in range(H)]

cost = solve()
if cost <= K:
    print('Yes')
else:
    print('No')
0