結果

問題 No.124 門松列(3)
ユーザー convexineqconvexineq
提出日時 2020-12-18 21:48:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 93 ms / 5,000 ms
コード長 675 bytes
コンパイル時間 1,502 ms
コンパイル使用メモリ 81,508 KB
実行使用メモリ 76,592 KB
最終ジャッジ日時 2023-10-21 08:24:11
合計ジャッジ時間 2,815 ms
ジャッジサーバーID
(参考情報)
judge15 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
65,876 KB
testcase_01 AC 43 ms
55,500 KB
testcase_02 AC 44 ms
55,500 KB
testcase_03 AC 93 ms
76,592 KB
testcase_04 AC 46 ms
61,252 KB
testcase_05 AC 47 ms
61,252 KB
testcase_06 AC 44 ms
55,500 KB
testcase_07 AC 43 ms
55,500 KB
testcase_08 AC 43 ms
55,500 KB
testcase_09 AC 43 ms
55,500 KB
testcase_10 AC 43 ms
55,500 KB
testcase_11 AC 42 ms
55,500 KB
testcase_12 AC 44 ms
55,500 KB
testcase_13 AC 43 ms
55,500 KB
testcase_14 AC 44 ms
55,500 KB
testcase_15 AC 44 ms
55,500 KB
testcase_16 AC 52 ms
61,544 KB
testcase_17 AC 44 ms
55,500 KB
testcase_18 AC 45 ms
55,500 KB
testcase_19 AC 45 ms
55,500 KB
testcase_20 AC 50 ms
61,216 KB
testcase_21 AC 44 ms
55,500 KB
testcase_22 AC 44 ms
55,500 KB
testcase_23 AC 47 ms
61,252 KB
testcase_24 AC 47 ms
61,252 KB
testcase_25 AC 48 ms
61,252 KB
testcase_26 AC 46 ms
59,204 KB
testcase_27 AC 46 ms
59,204 KB
testcase_28 AC 49 ms
61,252 KB
testcase_29 AC 49 ms
61,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

w,h,*b = map(int,open(0).read().split())
M = 2**15
from collections import deque
q = deque([M,w*M])
d = {M:1,w*M:1}

def check(c,x1,x2,delta):
    if b[x1] == b[c] or c*M+x2 in d: return
    if delta*(b[c]-b[x2]) < 0:
        q.append(c*M+x2)
        d[c*M+x2] = d[x] + 1

while q:
    x = q.popleft()
    x1,x2 = x%M, x//M
    h2,w2 = x2//w, x2%w
    delta = b[x2] - b[x1]
    if h2: check(x2-w,x1,x2,delta)
    if h2+1 < h: check(x2+w,x1,x2,delta)
    if w2: check(x2-1,x1,x2,delta)
    if w2+1 < w: check(x2+1,x1,x2,delta)

ans = INF = 10**9
for c in [(w*h-1)*M + (w*h-2), (w*h-1)*M + (w*h-1-w)]:
    if c in d:
        ans = min(ans,d[c])
print(ans if ans != INF else -1)
0