結果

問題 No.323 yuki国
ユーザー H3PO4
提出日時 2020-08-26 09:49:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,536 ms / 5,000 ms
コード長 1,077 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 473,044 KB
最終ジャッジ日時 2024-11-07 00:29:27
合計ジャッジ時間 39,676 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

import itertools
from collections import deque
H, W = map(int, input().split())
A, Si, Sj = map(int, input().split())
B, Gi, Gj = map(int, input().split())
M = [input() for _ in range(H)]
def point2int(h, w, x):
"""
H*W*1200
(h,w,x) → 1200*W*h+1200*w+x
"""
return 1200 * W * h + 1200 * w + x
Graph = [[] for _ in range(H * W * 1200)]
for h, w in itertools.product(range(H), range(W)):
n = (1 if M[h][w] == '*' else -1)
#
for dh, dw in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
if 0 <= h - dh < H and 0 <= w - dw < W:
for x in range(1200):
if 1 <= x - n < 1200:
Graph[point2int(h - dh, w - dw, x - n)].append(point2int(h, w, x))
S = point2int(Si, Sj, A)
G = point2int(Gi, Gj, B)
# dfs
d = deque([S])
visited = [False] * (H * W * 1200)
while d:
v = d.pop()
if v == G:
print('Yes')
break
visited[v] = True
for x in Graph[v]:
if not visited[x]:
d.append(x)
else:
print('No')
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0