結果

問題 No.3063 幅優先探索
ユーザー KodaiKodai
提出日時 2020-04-01 22:36:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 768 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 10,996 KB
実行使用メモリ 17,864 KB
最終ジャッジ日時 2023-09-09 19:15:34
合計ジャッジ時間 1,190 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,340 KB
testcase_01 AC 16 ms
8,336 KB
testcase_02 AC 16 ms
8,280 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 16 ms
8,152 KB
testcase_09 AC 15 ms
8,212 KB
testcase_10 AC 15 ms
8,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

R, C = list(map(int, input().split(" ")))
sy, sx = list(map(int, input().split(" ")))
gy, gx = list(map(int, input().split(" ")))
field_list = []
position_list = []
for i in range(R):
    temp = input()
    temp_list = []
    for j in temp:
        temp_list.append(j)
    field_list.append(temp_list)
# print(field_list)


def BFF(x, y, count):
    if x == gx-1 and y == gy-1:
        print(count)
        exit()
    for mx, my in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
        if 0 <= x+mx < C and 0 <= y+my < R:
            if (x+mx, y+my) not in position_list:
                if field_list[y+my][x+mx] == ".":
                    position_list.append((x+mx, y+my))
                    BFF(x+mx, y+my, count+1)


position_list.append((sx-1, sy-1))
BFF(sx-1, sy-1, 0)
0