結果
| 問題 | No.323 yuki国 |
| コンテスト | |
| ユーザー |
tktk_snsn
|
| 提出日時 | 2021-01-04 03:24:36 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 2,065 ms / 5,000 ms |
| コード長 | 1,160 bytes |
| コンパイル時間 | 236 ms |
| コンパイル使用メモリ | 81,920 KB |
| 実行使用メモリ | 198,656 KB |
| 最終ジャッジ日時 | 2024-10-13 21:05:08 |
| 合計ジャッジ時間 | 32,459 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 6 |
| other | AC * 32 |
ソースコード
from collections import deque
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
DX = (-1, 0, 1, 0, -1, -1, 1, 1)
DY = (0, 1, 0, -1, -1, 1, -1, 1)
DX = DX[:4]
DY = DY[:4]
H, W = map(int, input().split())
A, sx, sy = map(int, input().split())
B, gx, gy = map(int, input().split())
sx += 1
sy += 1
gx += 1
gy += 1
G = [[0] * (W + 2) for _ in range(H + 2)]
for i in range(1, H + 1):
for j, x in enumerate(input().rstrip(), 1):
if x == "*":
G[i][j] = 1
else:
G[i][j] = -1
U = 1000 + 50 * 50
dist = [[[-1] * (U + 1) for _ in range(W + 2)] for _ in range(H + 2)]
dist[sx][sy][A] = 0
que = deque([(sx, sy, A)])
while que:
x, y, a = que.popleft()
d = dist[x][y][a]
for dx, dy in zip(DX, DY):
nx = x + dx
ny = y + dy
if G[nx][ny] == 1 and a < U and dist[nx][ny][a + 1] == -1:
dist[nx][ny][a + 1] = d + 1
que.append((nx, ny, a + 1))
if G[nx][ny] == -1 and a > 1 and dist[nx][ny][a - 1] == -1:
dist[nx][ny][a - 1] = d + 1
que.append((nx, ny, a - 1))
if dist[gx][gy][B] == -1:
print("No")
else:
print("Yes")
tktk_snsn