結果
| 問題 | 
                            No.2096 Rage With Our Friends
                             | 
                    
| コンテスト | |
| ユーザー | 
                             AngrySadEight
                         | 
                    
| 提出日時 | 2022-09-14 23:44:04 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 2,458 bytes | 
| コンパイル時間 | 453 ms | 
| コンパイル使用メモリ | 82,528 KB | 
| 実行使用メモリ | 849,924 KB | 
| 最終ジャッジ日時 | 2024-12-15 12:32:55 | 
| 合計ジャッジ時間 | 56,260 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 WA * 2 | 
| other | AC * 5 WA * 15 TLE * 5 MLE * 2 | 
ソースコード
from collections import deque
H, W = map(int, input().split())
sx, sy, gx, gy = map(int, input().split())
sx -= 1
sy -= 1
gx -= 1
gy -= 1
S = []
for i in range(H):
    s = str(input())
    S.append(s)
calc_highest_x = [H - 1 for _ in range(W)]
highest_x = [[H - 1 for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            calc_highest_x[j] = i
        highest_x[i][j] = calc_highest_x[j]
INF = 1 << 24
isvisited = [[False for _ in range(W)] for _ in range(H)]
dist = [[INF for _ in range(W)] for _ in range(H)]
dq = deque()
dq.appendleft([sx, sy])
dist[sx][sy] = 0
while len(dq):
    px, py = dq.popleft()
    if px == gx and py == gy:
        print(dist[gx][gy])
        exit()
    if isvisited[px][py]:
        continue
    isvisited[px][py] = True
    if py - 1 >= 0:
        next_x = min(H - 1, px + 1)
        next_x = highest_x[next_x][py - 1]
        dq.appendleft([next_x, py - 1])
        dist[next_x][py - 1] = min(dist[next_x][py - 1], dist[px][py])
    
    if py + 1 < W:
        next_x = min(H - 1, px + 1)
        next_x = highest_x[next_x][py + 1]
        dq.appendleft([next_x, py + 1])
        dist[next_x][py + 1] = min(dist[next_x][py + 1], dist[px][py])
    
    if py - 2 >= 0:
        next_x = min(H - 1, px + 1)
        next_x = highest_x[next_x][py - 2]
        dq.append([next_x, py - 2])
        dist[next_x][py - 2] = min(dist[next_x][py - 2], dist[px][py] + 1)
    if py - 2 >= 0:
        diffs_x = -(highest_x[px][py - 1] - px)
        next_x = highest_x[px][py - 1] + 1 + diffs_x // 2
        next_x = highest_x[min(H - 1, next_x)][py - 2]
        dq.appendleft([next_x, py - 2])
        dist[next_x][py - 2] = min(dist[next_x][py - 2], dist[px][py])
    if py + 2 < W:
        next_x = min(H - 1, px + 1)
        next_x = highest_x[next_x][py + 2]
        dq.append([next_x, py + 2])
        dist[next_x][py + 2] = min(dist[next_x][py + 2], dist[px][py] + 1)
    if py + 2 < W:
        diffs_x = -(highest_x[px][py + 1] - px)
        next_x = highest_x[px][py + 1] + 1 + diffs_x // 2
        next_x = highest_x[min(H - 1, next_x)][py + 2]
        dq.appendleft([next_x, py + 2])
        dist[next_x][py + 2] = min(dist[next_x][py + 2], dist[px][py])
    if 0 <= py < W:
        next_x = min(H - 1, px + 1)
        next_x = highest_x[next_x][py]
        dq.append([next_x, py])
        dist[next_x][py] = min(dist[next_x][py], dist[px][py] + 1)
print(-1)
            
            
            
        
            
AngrySadEight