結果

問題 No.8063 幅優先探索
コンテスト
ユーザー Kodai
提出日時 2020-04-01 22:36:05
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
WA  
実行時間 -
コード長 768 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 649 ms
コンパイル使用メモリ 20,824 KB
実行使用メモリ 29,876 KB
最終ジャッジ日時 2026-03-15 06:45:36
合計ジャッジ時間 2,790 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 4 WA * 3 RE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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