結果

問題 No.323 yuki国
ユーザー H3PO4H3PO4
提出日時 2020-08-26 09:49:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,353 ms / 5,000 ms
コード長 1,077 bytes
コンパイル時間 155 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 473,088 KB
最終ジャッジ日時 2024-04-24 15:53:22
合計ジャッジ時間 37,395 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
68,352 KB
testcase_01 AC 59 ms
63,872 KB
testcase_02 AC 73 ms
71,552 KB
testcase_03 AC 99 ms
82,688 KB
testcase_04 AC 73 ms
68,608 KB
testcase_05 AC 91 ms
79,616 KB
testcase_06 AC 75 ms
71,168 KB
testcase_07 AC 88 ms
78,464 KB
testcase_08 AC 1,891 ms
431,872 KB
testcase_09 AC 1,821 ms
431,488 KB
testcase_10 AC 50 ms
59,008 KB
testcase_11 AC 60 ms
64,000 KB
testcase_12 AC 60 ms
63,872 KB
testcase_13 AC 1,822 ms
453,376 KB
testcase_14 AC 2,353 ms
431,872 KB
testcase_15 AC 1,911 ms
431,744 KB
testcase_16 AC 1,929 ms
432,000 KB
testcase_17 AC 1,482 ms
443,264 KB
testcase_18 AC 521 ms
188,800 KB
testcase_19 AC 1,254 ms
301,568 KB
testcase_20 AC 1,732 ms
464,768 KB
testcase_21 AC 2,326 ms
472,320 KB
testcase_22 AC 1,655 ms
464,384 KB
testcase_23 AC 2,197 ms
473,088 KB
testcase_24 AC 1,826 ms
431,744 KB
testcase_25 AC 1,831 ms
431,872 KB
testcase_26 AC 1,963 ms
431,744 KB
testcase_27 AC 1,789 ms
431,616 KB
testcase_28 AC 1,811 ms
431,744 KB
testcase_29 AC 1,847 ms
431,488 KB
testcase_30 AC 73 ms
70,912 KB
testcase_31 AC 72 ms
70,400 KB
testcase_32 AC 75 ms
72,576 KB
testcase_33 AC 66 ms
68,480 KB
testcase_34 AC 84 ms
78,848 KB
testcase_35 AC 64 ms
67,840 KB
testcase_36 AC 88 ms
77,824 KB
testcase_37 AC 65 ms
68,736 KB
権限があれば一括ダウンロードができます

ソースコード

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')
0