結果

問題 No.323 yuki国
ユーザー はむ吉🐹
提出日時 2016-03-10 22:42:41
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 1,730 bytes
コンパイル時間 118 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 170,196 KB
最終ジャッジ日時 2024-09-24 17:42:49
合計ジャッジ時間 7,173 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 2 TLE * 1 -- * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import collections


State = collections.namedtuple("State", "size r c")


class BreadthFirstSearch(object):

    def __init__(self, height, width, start, goal, stage):
        self.height = height
        self.width = width
        self.limit = 3500
        self.start = start
        self.goal = goal
        self.stage = stage
        self.deltas = [(1, 0), (-1, 0), (0, 1), (0, -1)]
        self.possible = collections.defaultdict(bool)

    def judge(self):
        self.possible[self.start] = True
        q = collections.deque()
        q.append(self.start)
        while q:
            state0 = q.popleft()
            if state0 == self.goal:
                break
            for dr, dc in self.deltas:
                (r, c) = (state0.r + dr, state0.c + dc)
                if r < 0 or r >= self.height or c < 0 or c >= self.width:
                    continue
                size = state0.size
                if self.stage[r][c] == "*":
                    size += 1
                else:
                    size -= 1
                if size <= 0 or size > self.limit:
                    continue
                state = State(size, r, c)
                if self.possible[state]:
                    continue
                self.possible[state] = True
                q.append(state)
        return self.possible[self.goal]


def main():
    height, width = map(int, input().split())
    start = State(*map(int, input().split()))
    goal = State(*map(int, input().split()))
    stage = [input() for _ in range(height)]
    bfs = BreadthFirstSearch(height, width, start, goal, stage)
    print("Yes" if bfs.judge() else "No")


if __name__ == '__main__':
    main()
0