結果

問題 No.323 yuki国
ユーザー はむ吉🐹
提出日時 2016-03-10 22:45:05
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,728 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 82,596 KB
実行使用メモリ 758,336 KB
最終ジャッジ日時 2024-09-24 17:46:37
合計ジャッジ時間 7,549 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 2 MLE * 1 -- * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env pypy3
# -*- 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 = 3200
        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