結果

問題 No.323 yuki国
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-03-10 23:02:07
言語 PyPy2
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,749 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 77,400 KB
実行使用メモリ 740,692 KB
最終ジャッジ日時 2023-10-24 22:49:07
合計ジャッジ時間 39,951 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 AC 80 ms
78,116 KB
testcase_02 AC 81 ms
78,116 KB
testcase_03 AC 85 ms
78,324 KB
testcase_04 AC 80 ms
78,132 KB
testcase_05 AC 153 ms
85,824 KB
testcase_06 AC 123 ms
82,092 KB
testcase_07 AC 82 ms
78,252 KB
testcase_08 TLE -
testcase_09 AC 3,082 ms
404,420 KB
testcase_10 AC 82 ms
78,264 KB
testcase_11 AC 102 ms
80,228 KB
testcase_12 AC 102 ms
80,224 KB
testcase_13 AC 2,822 ms
404,268 KB
testcase_14 TLE -
testcase_15 AC 2,223 ms
346,328 KB
testcase_16 TLE -
testcase_17 AC 2,848 ms
404,504 KB
testcase_18 AC 141 ms
82,844 KB
testcase_19 AC 3,448 ms
425,348 KB
testcase_20 AC 173 ms
87,160 KB
testcase_21 MLE -
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 pypy
# -*- 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 = 2000
        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():
    input = raw_input
    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