結果

問題 No.323 yuki国
ユーザー tktk_snsntktk_snsn
提出日時 2021-01-04 03:24:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,134 ms / 5,000 ms
コード長 1,160 bytes
コンパイル時間 494 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 198,348 KB
最終ジャッジ日時 2024-04-21 22:39:30
合計ジャッジ時間 32,336 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,272 KB
testcase_01 AC 56 ms
65,024 KB
testcase_02 AC 44 ms
54,784 KB
testcase_03 AC 115 ms
80,000 KB
testcase_04 AC 69 ms
73,524 KB
testcase_05 AC 82 ms
78,080 KB
testcase_06 AC 69 ms
71,424 KB
testcase_07 AC 44 ms
55,552 KB
testcase_08 AC 1,780 ms
194,560 KB
testcase_09 AC 1,748 ms
194,876 KB
testcase_10 AC 44 ms
53,968 KB
testcase_11 AC 57 ms
65,280 KB
testcase_12 AC 56 ms
65,152 KB
testcase_13 AC 1,710 ms
194,840 KB
testcase_14 AC 1,829 ms
194,752 KB
testcase_15 AC 641 ms
163,612 KB
testcase_16 AC 1,642 ms
197,888 KB
testcase_17 AC 1,797 ms
194,956 KB
testcase_18 AC 439 ms
112,256 KB
testcase_19 AC 1,011 ms
149,504 KB
testcase_20 AC 2,132 ms
196,644 KB
testcase_21 AC 2,011 ms
198,348 KB
testcase_22 AC 2,078 ms
198,208 KB
testcase_23 AC 2,134 ms
196,612 KB
testcase_24 AC 650 ms
162,524 KB
testcase_25 AC 637 ms
162,304 KB
testcase_26 AC 1,852 ms
194,816 KB
testcase_27 AC 1,929 ms
195,044 KB
testcase_28 AC 1,991 ms
194,904 KB
testcase_29 AC 1,836 ms
194,824 KB
testcase_30 AC 43 ms
54,652 KB
testcase_31 AC 62 ms
68,096 KB
testcase_32 AC 69 ms
72,320 KB
testcase_33 AC 60 ms
67,456 KB
testcase_34 AC 79 ms
77,696 KB
testcase_35 AC 42 ms
54,528 KB
testcase_36 AC 72 ms
73,600 KB
testcase_37 AC 67 ms
71,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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