結果

問題 No.424 立体迷路
ユーザー ヒッキープログラミングするスレヒッキープログラミングするスレ
提出日時 2016-09-23 00:18:45
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,950 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 11,148 KB
実行使用メモリ 8,528 KB
最終ジャッジ日時 2023-09-18 16:52:14
合計ジャッジ時間 1,717 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,356 KB
testcase_01 AC 18 ms
8,424 KB
testcase_02 AC 17 ms
8,320 KB
testcase_03 AC 18 ms
8,384 KB
testcase_04 AC 17 ms
8,476 KB
testcase_05 AC 17 ms
8,528 KB
testcase_06 AC 17 ms
8,308 KB
testcase_07 AC 17 ms
8,512 KB
testcase_08 AC 17 ms
8,272 KB
testcase_09 AC 17 ms
8,452 KB
testcase_10 AC 17 ms
8,468 KB
testcase_11 AC 17 ms
8,308 KB
testcase_12 AC 18 ms
8,340 KB
testcase_13 AC 18 ms
8,352 KB
testcase_14 AC 18 ms
8,496 KB
testcase_15 AC 17 ms
8,512 KB
testcase_16 AC 17 ms
8,524 KB
testcase_17 AC 17 ms
8,396 KB
testcase_18 AC 17 ms
8,408 KB
testcase_19 AC 17 ms
8,364 KB
testcase_20 AC 17 ms
8,324 KB
testcase_21 AC 17 ms
8,340 KB
testcase_22 AC 18 ms
8,332 KB
testcase_23 AC 17 ms
8,356 KB
testcase_24 AC 32 ms
8,360 KB
testcase_25 AC 32 ms
8,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h, w = list(map(int, input().split()))
sy, sx, gy, gx = list(map(int, input().split()))
b = []
for _ in range(h):
    b.append(input().strip())

f = [[True] * w for _ in range(h)]

t = [[sy - 1, sx - 1]]
f[sy - 1][sx - 1] = False

while len(t) > 0:
    s = []
    for y, x in t:
        p = int(b[y][x])
        if x > 0:
            q = int(b[y][x - 1])
            if f[y][x - 1] and abs(p - q) < 2:
                f[y][x - 1] = False
                s.append([y, x - 1])
        if y > 0:
            q = int(b[y - 1][x])
            if f[y - 1][x] and abs(p - q) < 2:
                f[y - 1][x] = False
                s.append([y - 1, x])
        if x < w - 1:
            q = int(b[y][x + 1])
            if f[y][x + 1] and abs(p - q) < 2:
                f[y][x + 1] = False
                s.append([y, x + 1])
        if y < h - 1:
            q = int(b[y + 1][x])
            if f[y + 1][x] and abs(p - q) < 2:
                f[y + 1][x] = False
                s.append([y + 1, x])
        if x > 1:
            q1 = int(b[y][x - 1])
            q2 = int(b[y][x - 2])
            if f[y][x - 2] and p > q1 and p == q2:
                f[y][x - 2] = False
                s.append([y, x - 2])
        if y > 1:
            q1 = int(b[y - 1][x])
            q2 = int(b[y - 2][x])
            if f[y - 2][x] and p > q1 and p == q2:
                f[y - 2][x] = False
                s.append([y - 2, x])
        if x < w - 2:
            q1 = int(b[y][x + 1])
            q2 = int(b[y][x + 2])
            if f[y][x + 2] and p > q1 and p == q2:
                f[y][x + 2] = False
                s.append([y, x + 2])
        if y < h - 2:
            q1 = int(b[y + 1][x])
            q2 = int(b[y + 2][x])
            if f[y + 2][x] and p > q1 and p == q2:
                f[y + 2][x] = False
                s.append([y + 2, x])
    t = s
    if f[gy - 1][gx - 1] == False:
        break

print('NO' if f[gy - 1][gx - 1] else 'YES')

0