提出 #68750355


ソースコード 拡げる

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

for i in range(H):
    for j in range(W):
        a = field[i][j]
        if a == 'S':
            si, sj = i, j
        
        if a == 'G':
            gi, gj = i, j


from collections import defaultdict, deque
            
dist = defaultdict(int)

q = deque()

q.append((si, sj, 0))
dist[(si, sj, 0)] = 0

while q:
    i, j, pressed = q.popleft()
    for di, dj in [(-1, 0), (0, 1), (1, 0), (0, -1)]:
        ni, nj = i + di, j + dj
        if 0 <= ni < H and 0 <= nj < W:
            f = field[ni][nj]
            if f == '#': continue
            if f == 'o' and pressed: continue
            if f == 'x' and not pressed: continue
            newPressed = pressed ^ (f == '?')
            newKey = (ni, nj, newPressed)
            if newKey in dist:
                continue
            dist[newKey] = dist[i, j, pressed] + 1
            q.append(newKey)
            if f == 'G':
                print(dist[newKey])
                exit(0)

print(-1)

提出情報

提出日時
問題 D - Toggle Maze
ユーザ catupper
言語 Python (PyPy 3.10-v7.3.12)
得点 400
コード長 1069 Byte
結果 AC
実行時間 699 ms
メモリ 247080 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 76804 KiB
00_sample_01.txt AC 73 ms 76860 KiB
00_sample_02.txt AC 74 ms 76900 KiB
01_handmade_00.txt AC 496 ms 196696 KiB
01_handmade_01.txt AC 510 ms 197024 KiB
01_handmade_02.txt AC 512 ms 196632 KiB
01_handmade_03.txt AC 500 ms 196768 KiB
01_handmade_04.txt AC 74 ms 76864 KiB
01_handmade_05.txt AC 75 ms 77016 KiB
01_handmade_06.txt AC 75 ms 76868 KiB
01_handmade_07.txt AC 73 ms 77032 KiB
01_handmade_08.txt AC 75 ms 76800 KiB
01_handmade_09.txt AC 282 ms 135076 KiB
01_handmade_10.txt AC 293 ms 134308 KiB
01_handmade_11.txt AC 126 ms 92904 KiB
01_handmade_12.txt AC 699 ms 247080 KiB
01_handmade_13.txt AC 225 ms 110256 KiB
01_handmade_14.txt AC 364 ms 152704 KiB
02_random_00.txt AC 78 ms 81208 KiB
02_random_01.txt AC 200 ms 106720 KiB
02_random_02.txt AC 115 ms 85080 KiB
02_random_03.txt AC 297 ms 127464 KiB
02_random_04.txt AC 78 ms 81140 KiB
02_random_05.txt AC 315 ms 132432 KiB
02_random_06.txt AC 194 ms 106648 KiB
02_random_07.txt AC 122 ms 86492 KiB
02_random_08.txt AC 85 ms 83308 KiB
02_random_09.txt AC 261 ms 118260 KiB
02_random_10.txt AC 84 ms 83608 KiB
02_random_11.txt AC 379 ms 149636 KiB
02_random_12.txt AC 85 ms 83932 KiB
02_random_13.txt AC 130 ms 88340 KiB
02_random_14.txt AC 329 ms 144920 KiB
02_random_15.txt AC 103 ms 83916 KiB
02_random_16.txt AC 365 ms 154228 KiB
02_random_17.txt AC 108 ms 84604 KiB
02_random_18.txt AC 311 ms 132876 KiB
02_random_19.txt AC 125 ms 86908 KiB
02_random_20.txt AC 228 ms 108472 KiB
02_random_21.txt AC 78 ms 80864 KiB
02_random_22.txt AC 255 ms 114612 KiB
02_random_23.txt AC 96 ms 84100 KiB
02_random_24.txt AC 118 ms 88684 KiB
02_random_25.txt AC 96 ms 83664 KiB
02_random_26.txt AC 148 ms 94448 KiB
02_random_27.txt AC 106 ms 85284 KiB
02_random_28.txt AC 169 ms 99340 KiB
02_random_29.txt AC 154 ms 96560 KiB
02_random_30.txt AC 270 ms 123932 KiB
02_random_31.txt AC 111 ms 87904 KiB
02_random_32.txt AC 158 ms 97260 KiB
02_random_33.txt AC 151 ms 97364 KiB
02_random_34.txt AC 149 ms 98568 KiB
02_random_35.txt AC 122 ms 86504 KiB
02_random_36.txt AC 174 ms 97852 KiB
02_random_37.txt AC 251 ms 114392 KiB
02_random_38.txt AC 137 ms 89792 KiB
02_random_39.txt AC 358 ms 136256 KiB
02_random_40.txt AC 545 ms 186300 KiB
02_random_41.txt AC 90 ms 83536 KiB
02_random_42.txt AC 90 ms 83508 KiB
02_random_43.txt AC 94 ms 83544 KiB
02_random_44.txt AC 92 ms 83400 KiB
02_random_45.txt AC 91 ms 83656 KiB
02_random_46.txt AC 89 ms 84012 KiB
02_random_47.txt AC 85 ms 82440 KiB
02_random_48.txt AC 84 ms 81620 KiB