結果

問題 No.124 門松列(3)
ユーザー mkawa2mkawa2
提出日時 2020-01-20 23:46:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 32 ms / 5,000 ms
コード長 1,046 bytes
コンパイル時間 132 ms
コンパイル使用メモリ 11,068 KB
実行使用メモリ 9,632 KB
最終ジャッジ日時 2023-09-15 21:49:16
合計ジャッジ時間 1,913 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
8,852 KB
testcase_01 AC 19 ms
8,556 KB
testcase_02 AC 20 ms
8,544 KB
testcase_03 AC 32 ms
9,632 KB
testcase_04 AC 21 ms
8,648 KB
testcase_05 AC 20 ms
8,556 KB
testcase_06 AC 19 ms
8,488 KB
testcase_07 AC 19 ms
8,568 KB
testcase_08 AC 18 ms
8,700 KB
testcase_09 AC 19 ms
8,564 KB
testcase_10 AC 18 ms
8,500 KB
testcase_11 AC 18 ms
8,556 KB
testcase_12 AC 19 ms
8,552 KB
testcase_13 AC 18 ms
8,636 KB
testcase_14 AC 19 ms
8,560 KB
testcase_15 AC 19 ms
8,728 KB
testcase_16 AC 20 ms
8,692 KB
testcase_17 AC 19 ms
8,736 KB
testcase_18 AC 19 ms
8,556 KB
testcase_19 AC 19 ms
8,508 KB
testcase_20 AC 19 ms
8,576 KB
testcase_21 AC 19 ms
8,584 KB
testcase_22 AC 18 ms
8,732 KB
testcase_23 AC 19 ms
8,524 KB
testcase_24 AC 20 ms
8,640 KB
testcase_25 AC 20 ms
8,572 KB
testcase_26 AC 19 ms
8,572 KB
testcase_27 AC 19 ms
8,564 KB
testcase_28 AC 20 ms
8,624 KB
testcase_29 AC 21 ms
8,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
from collections import *
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]

def main():
    w, h = MI()
    mm = LLI(h)
    fin = set()
    bfs = deque()
    # [距離,行,列,前のマスの値]
    bfs.append([0, 0, 0, -1])
    bfs.append([0, 0, 0, 10])
    fin=set()
    while bfs:
        d, i, j, pm = bfs.popleft()
        if (i, j, pm) in fin:continue
        fin.add((i, j, pm))
        m = mm[i][j]
        for di, dj in dij:
            ni, nj = i + di, j + dj
            if ni < 0 or nj < 0 or ni >= h or nj >= w: continue
            nm = mm[ni][nj]
            if nm == m or nm==pm or pm<m<nm or pm>m>nm: continue
            if (ni,nj,m) in fin:continue
            if (ni, nj) == (h - 1, w - 1):
                print(d + 1)
                exit()
            bfs.append([d + 1, ni, nj, m])
    print(-1)

main()
0