結果

問題 No.323 yuki国
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-03-10 22:42:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,730 bytes
コンパイル時間 428 ms
コンパイル使用メモリ 12,184 KB
実行使用メモリ 15,324 KB
最終ジャッジ日時 2023-10-24 22:36:11
合計ジャッジ時間 7,646 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,336 KB
testcase_01 AC 30 ms
10,312 KB
testcase_02 AC 30 ms
10,312 KB
testcase_03 AC 31 ms
10,328 KB
testcase_04 AC 30 ms
10,316 KB
testcase_05 AC 156 ms
15,324 KB
testcase_06 AC 68 ms
12,672 KB
testcase_07 AC 30 ms
10,312 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

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