結果

問題 No.424 立体迷路
ユーザー ヒッキープログラミングするスレヒッキープログラミングするスレ
提出日時 2016-09-23 00:17:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,949 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-28 20:02:14
合計ジャッジ時間 1,773 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
11,008 KB
testcase_01 RE -
testcase_02 AC 34 ms
11,136 KB
testcase_03 AC 35 ms
11,008 KB
testcase_04 RE -
testcase_05 AC 32 ms
10,880 KB
testcase_06 AC 31 ms
10,880 KB
testcase_07 AC 32 ms
11,008 KB
testcase_08 AC 31 ms
11,008 KB
testcase_09 AC 31 ms
10,880 KB
testcase_10 RE -
testcase_11 AC 31 ms
11,008 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 30 ms
11,008 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 32 ms
10,880 KB
testcase_18 AC 31 ms
11,008 KB
testcase_19 RE -
testcase_20 AC 32 ms
11,008 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 32 ms
10,880 KB
testcase_24 RE -
testcase_25 RE -
権限があれば一括ダウンロードができます

ソースコード

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.appen([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