提出 #68754619


ソースコード 拡げる

from collections import deque

di = [1, -1, 0, 0]
dj = [0, 0, 1, -1]

H, W = map(int, input().split())
grid = [input() for _ in range(H)]

operCnt = [[[-1] * 2 for _ in range(W)] for _ in range(H)]

start = (0, 0)
goal = (0, 0)
for i in range(H):
    for j in range(W):
        if grid[i][j] == "S":
            start = (i, j)
        if grid[i][j] == "G":
            goal = (i, j)

si, sj = start
operCnt[si][sj][0] = 0

queue = deque([(start, 0)])
while queue:
    coord, switched = queue.popleft()
    i, j = coord

    for k in range(4):
        ni = i + di[k]
        nj = j + dj[k]

        if not (0 <= ni < H) or not (0 <= nj < W):
            continue
        if grid[ni][nj] == "#":
            continue
        if (switched and grid[ni][nj] == "o") or (not switched and grid[ni][nj] == "x"):
            continue

        nextSwitched = switched
        if grid[ni][nj] == "?":
            nextSwitched ^= 1

        if operCnt[ni][nj][nextSwitched] != -1:
            continue

        operCnt[ni][nj][nextSwitched] = operCnt[i][j][switched] + 1
        queue.append(((ni, nj), nextSwitched))

i, j = goal
answer = operCnt[i][j][0]

if operCnt[i][j][1] != -1:
    if answer == -1:
        answer = operCnt[i][j][1]
    else:
        answer = min(answer, operCnt[i][j][1])

print(answer)

提出情報

提出日時
問題 D - Toggle Maze
ユーザ skuru
言語 Python (PyPy 3.10-v7.3.12)
得点 400
コード長 1358 Byte
結果 AC
実行時間 242 ms
メモリ 109568 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 3
AC × 67
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 01_handmade_08.txt, 01_handmade_09.txt, 01_handmade_10.txt, 01_handmade_11.txt, 01_handmade_12.txt, 01_handmade_13.txt, 01_handmade_14.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt, 02_random_21.txt, 02_random_22.txt, 02_random_23.txt, 02_random_24.txt, 02_random_25.txt, 02_random_26.txt, 02_random_27.txt, 02_random_28.txt, 02_random_29.txt, 02_random_30.txt, 02_random_31.txt, 02_random_32.txt, 02_random_33.txt, 02_random_34.txt, 02_random_35.txt, 02_random_36.txt, 02_random_37.txt, 02_random_38.txt, 02_random_39.txt, 02_random_40.txt, 02_random_41.txt, 02_random_42.txt, 02_random_43.txt, 02_random_44.txt, 02_random_45.txt, 02_random_46.txt, 02_random_47.txt, 02_random_48.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 75 ms 76736 KiB
00_sample_01.txt AC 77 ms 77060 KiB
00_sample_02.txt AC 77 ms 76752 KiB
01_handmade_00.txt AC 203 ms 106836 KiB
01_handmade_01.txt AC 210 ms 106996 KiB
01_handmade_02.txt AC 200 ms 107428 KiB
01_handmade_03.txt AC 202 ms 107160 KiB
01_handmade_04.txt AC 75 ms 76880 KiB
01_handmade_05.txt AC 74 ms 77072 KiB
01_handmade_06.txt AC 75 ms 76784 KiB
01_handmade_07.txt AC 76 ms 76872 KiB
01_handmade_08.txt AC 76 ms 76820 KiB
01_handmade_09.txt AC 143 ms 105540 KiB
01_handmade_10.txt AC 148 ms 106276 KiB
01_handmade_11.txt AC 226 ms 109568 KiB
01_handmade_12.txt AC 221 ms 109408 KiB
01_handmade_13.txt AC 173 ms 105636 KiB
01_handmade_14.txt AC 169 ms 105568 KiB
02_random_00.txt AC 77 ms 81664 KiB
02_random_01.txt AC 177 ms 100204 KiB
02_random_02.txt AC 105 ms 84228 KiB
02_random_03.txt AC 189 ms 104340 KiB
02_random_04.txt AC 82 ms 81572 KiB
02_random_05.txt AC 206 ms 107148 KiB
02_random_06.txt AC 188 ms 103896 KiB
02_random_07.txt AC 205 ms 107232 KiB
02_random_08.txt AC 95 ms 88252 KiB
02_random_09.txt AC 209 ms 106956 KiB
02_random_10.txt AC 96 ms 87972 KiB
02_random_11.txt AC 201 ms 107236 KiB
02_random_12.txt AC 96 ms 87948 KiB
02_random_13.txt AC 131 ms 89136 KiB
02_random_14.txt AC 190 ms 103228 KiB
02_random_15.txt AC 104 ms 83832 KiB
02_random_16.txt AC 204 ms 107000 KiB
02_random_17.txt AC 107 ms 84300 KiB
02_random_18.txt AC 214 ms 107052 KiB
02_random_19.txt AC 116 ms 86056 KiB
02_random_20.txt AC 210 ms 107168 KiB
02_random_21.txt AC 80 ms 76780 KiB
02_random_22.txt AC 207 ms 107140 KiB
02_random_23.txt AC 106 ms 84452 KiB
02_random_24.txt AC 145 ms 98336 KiB
02_random_25.txt AC 107 ms 89640 KiB
02_random_26.txt AC 139 ms 92232 KiB
02_random_27.txt AC 119 ms 87880 KiB
02_random_28.txt AC 172 ms 107100 KiB
02_random_29.txt AC 134 ms 90164 KiB
02_random_30.txt AC 197 ms 107048 KiB
02_random_31.txt AC 130 ms 101516 KiB
02_random_32.txt AC 148 ms 105820 KiB
02_random_33.txt AC 135 ms 94880 KiB
02_random_34.txt AC 178 ms 106736 KiB
02_random_35.txt AC 126 ms 87084 KiB
02_random_36.txt AC 176 ms 96192 KiB
02_random_37.txt AC 154 ms 91756 KiB
02_random_38.txt AC 242 ms 108860 KiB
02_random_39.txt AC 218 ms 103872 KiB
02_random_40.txt AC 233 ms 109296 KiB
02_random_41.txt AC 94 ms 83532 KiB
02_random_42.txt AC 93 ms 83528 KiB
02_random_43.txt AC 101 ms 83696 KiB
02_random_44.txt AC 101 ms 83944 KiB
02_random_45.txt AC 95 ms 83196 KiB
02_random_46.txt AC 95 ms 83532 KiB
02_random_47.txt AC 102 ms 83588 KiB
02_random_48.txt AC 101 ms 83928 KiB