結果

問題 No.424 立体迷路
ユーザー nanaenanae
提出日時 2017-01-19 09:00:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,444 bytes
コンパイル時間 108 ms
コンパイル使用メモリ 10,740 KB
実行使用メモリ 8,840 KB
最終ジャッジ日時 2023-09-18 17:00:13
合計ジャッジ時間 1,985 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,036 KB
testcase_01 AC 18 ms
8,124 KB
testcase_02 AC 17 ms
7,992 KB
testcase_03 AC 17 ms
8,020 KB
testcase_04 AC 18 ms
8,044 KB
testcase_05 AC 17 ms
8,164 KB
testcase_06 AC 17 ms
8,164 KB
testcase_07 AC 17 ms
8,204 KB
testcase_08 AC 17 ms
8,076 KB
testcase_09 AC 17 ms
8,036 KB
testcase_10 AC 17 ms
8,020 KB
testcase_11 AC 17 ms
8,096 KB
testcase_12 AC 17 ms
8,056 KB
testcase_13 AC 17 ms
8,124 KB
testcase_14 AC 18 ms
8,076 KB
testcase_15 AC 17 ms
8,096 KB
testcase_16 AC 17 ms
8,136 KB
testcase_17 AC 18 ms
8,032 KB
testcase_18 AC 18 ms
8,172 KB
testcase_19 AC 18 ms
8,036 KB
testcase_20 AC 18 ms
8,164 KB
testcase_21 AC 17 ms
8,216 KB
testcase_22 AC 17 ms
8,008 KB
testcase_23 AC 17 ms
8,216 KB
testcase_24 AC 65 ms
8,792 KB
testcase_25 AC 65 ms
8,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 入力 
h, w = map(int, input().split())
sx, sy, gx, gy = map(lambda x: x - 1, map(int, input().split()))
# sx, sy, gx, gy = sx - 1, sy - 1, gx - 1, gy - 1

b = [[] for i in range(h)]

for i in range(h):
    line = input()

    for takasa in line:
        b[i].append(int(takasa))

# print(b)

dx = [1, 0, -1, 0, 2, 0, -2, 0,]
dy = [0, 1, 0 ,-1, 0, 2, 0, -2,]

ikeru = [[None] * w for i in range(h)]

# print(ikeru)

ikeru[sx][sy] = True
tugis = [(sx, sy)]
tansaku_zumi = set()

# print(tugis[0][0])

while tugis:
    cur = tugis.pop()

    for i in range(len(dx)):
        if 0 <= cur[0] + dx[i] < h and 0 <= cur[1] + dy[i] < w:
            if i > 3 and b[cur[0]][cur[1]] == b[cur[0] + dx[i]][cur[1] + dy[i]]:
                if b[cur[0]][cur[1]] > b[cur[0] + dx[i - 4]][cur[1] + dy[i - 4]]:
                    if (cur[0] + dx[i], cur[1] + dy[i]) not in tansaku_zumi:
                        ikeru[cur[0] + dx[i]][cur[1] + dy[i]] = True
                        tugis.append((cur[0] + dx[i], cur[1] + dy[i]))
            elif i <= 3 and abs(b[cur[0] + dx[i]][cur[1] + dy[i]] - b[cur[0]][cur[1]]) <= 1:
                if (cur[0] + dx[i], cur[1] + dy[i]) not in tansaku_zumi:
                    ikeru[cur[0] + dx[i]][cur[1] + dy[i]] = True
                    tugis.append((cur[0] + dx[i], cur[1] + dy[i]))

    tansaku_zumi.add(cur)

# print(sorted(list(tansaku_zumi)))

if (gx, gy) in tansaku_zumi:
    print('YES')
else:
    print('NO')
0