提出 #72583271


ソースコード 拡げる

from collections import deque

H, W = map(int, input().split())
S = [input() for _ in range(H)]
bfs = deque([(0, 0, 0)])
visited = set((0, 0))
while bfs:
    r, c, t = bfs.popleft()
    if r == H - 1 and c == W - 1:
        print(t)
        break
    for dr, dc in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
        nr, nc = r + dr, c + dc
        if 0 <= nr < H and 0 <= nc < W and not (nr, nc) in visited and S[r][c] != S[nr][nc]:
            visited.add((nr, nc))
            bfs.append((nr, nc, t + 1))
else:
    print(-1)

提出情報

提出日時
問題 F - EGFパス
ユーザ sugarcrash
言語 Python (PyPy 3.11-v7.3.20)
得点 100
コード長 536 Byte
結果 AC
実行時間 595 ms
メモリ 232824 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 100 / 100
結果
AC × 3
AC × 25
セット名 テストケース
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_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 68 ms 93860 KiB
00_sample_01.txt AC 65 ms 93428 KiB
00_sample_02.txt AC 65 ms 93912 KiB
01_random_00.txt AC 570 ms 232444 KiB
01_random_01.txt AC 434 ms 190892 KiB
01_random_02.txt AC 111 ms 118088 KiB
01_random_03.txt AC 204 ms 141792 KiB
01_random_04.txt AC 565 ms 232812 KiB
01_random_05.txt AC 583 ms 232824 KiB
01_random_06.txt AC 583 ms 232756 KiB
01_random_07.txt AC 86 ms 108892 KiB
01_random_08.txt AC 595 ms 215780 KiB
01_random_09.txt AC 85 ms 109012 KiB
01_random_10.txt AC 504 ms 224956 KiB
01_random_11.txt AC 501 ms 224940 KiB
01_random_12.txt AC 572 ms 232504 KiB
01_random_13.txt AC 578 ms 232588 KiB
01_random_14.txt AC 126 ms 123396 KiB
01_random_15.txt AC 287 ms 158364 KiB
01_random_16.txt AC 507 ms 207820 KiB
01_random_17.txt AC 445 ms 190724 KiB
01_random_18.txt AC 89 ms 109648 KiB
01_random_19.txt AC 576 ms 232576 KiB
01_random_20.txt AC 358 ms 175600 KiB
01_random_21.txt AC 145 ms 133952 KiB