提出 #72574990


ソースコード 拡げる

import sys,bisect
from heapq import heappop, heappush
from collections import deque, Counter, defaultdict
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353

H,W = mi()
S = [list(input()) for _ in range(H)]

q = deque()
q.append((0,0))
dp = [[-1]*W for _ in range(H)]
dp[0][0] = 0
while q:
    x,y = q.popleft()
    for dx,dy in [(0,1),(1,0),(0,-1),(-1,0)]:
        nx,ny = x+dx,y+dy
        if not(0<=nx<H and 0<=ny<W) or S[x][y]==S[nx][ny] or dp[nx][ny]!=-1:continue
        dp[nx][ny] = dp[x][y] + 1
        q.append((nx,ny))

print(dp[H-1][W-1])

提出情報

提出日時
問題 F - EGFパス
ユーザ guild2026_288
言語 Python (PyPy 3.11-v7.3.20)
得点 100
コード長 722 Byte
結果 AC
実行時間 261 ms
メモリ 162288 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 70 ms 96956 KiB
00_sample_01.txt AC 69 ms 96796 KiB
00_sample_02.txt AC 69 ms 96796 KiB
01_random_00.txt AC 260 ms 162200 KiB
01_random_01.txt AC 206 ms 146344 KiB
01_random_02.txt AC 92 ms 111704 KiB
01_random_03.txt AC 126 ms 122716 KiB
01_random_04.txt AC 256 ms 162236 KiB
01_random_05.txt AC 256 ms 162248 KiB
01_random_06.txt AC 256 ms 162288 KiB
01_random_07.txt AC 105 ms 148792 KiB
01_random_08.txt AC 249 ms 161160 KiB
01_random_09.txt AC 105 ms 148796 KiB
01_random_10.txt AC 214 ms 156348 KiB
01_random_11.txt AC 217 ms 156480 KiB
01_random_12.txt AC 261 ms 162212 KiB
01_random_13.txt AC 260 ms 162240 KiB
01_random_14.txt AC 97 ms 112708 KiB
01_random_15.txt AC 157 ms 130964 KiB
01_random_16.txt AC 235 ms 156164 KiB
01_random_17.txt AC 209 ms 146852 KiB
01_random_18.txt AC 82 ms 109316 KiB
01_random_19.txt AC 254 ms 162212 KiB
01_random_20.txt AC 183 ms 141416 KiB
01_random_21.txt AC 104 ms 113068 KiB