結果
| 問題 | No.3504 Insert Maze |
| コンテスト | |
| ユーザー |
Koi
|
| 提出日時 | 2026-04-18 00:40:31 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,070 bytes |
| 記録 | |
| コンパイル時間 | 251 ms |
| コンパイル使用メモリ | 85,376 KB |
| 実行使用メモリ | 148,352 KB |
| 最終ジャッジ日時 | 2026-04-18 00:41:58 |
| 合計ジャッジ時間 | 9,543 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 42 WA * 43 |
ソースコード
H, W = map(int, input().split())
S = [input() for _ in range(H)]
L = [(0,0)]
Seen = [[False] * W for _ in range(H)]
dx = [1, 0]
dy = [0, 1]
S_height = 0
S_width = 0
while len(L):
(x, y) = L.pop()
if(x == H - 1 and y == W - 1):
print(H + W - 2)
exit()
S_height = max(x, S_height)
S_width = max(y, S_width)
for k in range(2):
x2 = x + dx[k]
y2 = y + dy[k]
if(x2 < H and y2 < W and S[x2][y2] != "#" and not Seen[x2][y2]):
Seen[x2][y2] = True
L.append((x2, y2))
L = [(H - 1,W - 1)]
Seen = [[False] * W for _ in range(H)]
dx = [-1, 0]
dy = [0, -1]
G_height = H - 1
G_width = W - 1
while len(L):
(x, y) = L.pop()
G_height = min(x, G_height)
G_width = min(y, G_width)
for k in range(2):
x2 = x + dx[k]
y2 = y + dy[k]
if(0 <= x2 and 0 <= y2 and S[x2][y2] != "#" and not Seen[x2][y2]):
Seen[x2][y2] = True
L.append((x2, y2))
if(G_height - S_height <= 1 or G_width - G_height <= 1):
print(H + W -1)
else:
print(H + W)
Koi