結果

問題 No.3679 なんかでっかい虫リターンズ
コンテスト
ユーザー kidodesu
提出日時 2026-09-05 13:17:06
言語 PyPy3
(7.3.23)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 107 ms / 2,000 ms
+ 921µs
コード長 904 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 249 ms
コンパイル使用メモリ 95,956 KB
実行使用メモリ 88,064 KB
最終ジャッジ日時 2026-09-05 13:17:12
合計ジャッジ時間 3,336 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

h, w = list(map(int, input().split()))
sy, sx = list(map(lambda x: int(x)-1, input().split()))
gy0, gx0, gy1, gx1 = list(map(lambda x: int(x), input().split()))
gy0, gx0 = gy0-1, gx0-1
ty, tx = list(map(lambda x: int(x)-1, input().split()))
dp = [[[-1, -1, -1] for _ in range(w)] for _ in range(h)]
dp[sy][sx][0] = 0
B = [(sy, sx, 0)]
c = 0
while A:= B:
    B = []
    while A:
        y, x, a = A.pop()
        if not a and gy0 <= y < gy1 and gx0 <= x < gx1 and dp[y][x][1] == -1:
            dp[y][x][1] = c
            A.append((y, x, 1))
        if a == 1 and y == ty and x == tx and dp[y][x][2] == -1:
            dp[y][x][2] = c
            A.append((y, x, 2))
        for ny, nx in [(y, x-1), (y, x+1), (y-1, x), (y+1, x)]:
            if 0 <= ny < h and 0 <= nx < w and dp[ny][nx][a] == -1:
                dp[ny][nx][a] = c+1
                B.append((ny, nx, a))
    c += 1
print(dp[sy][sx][2])
0