結果

問題 No.124 門松列(3)
ユーザー convexineqconvexineq
提出日時 2020-12-18 21:44:37
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 706 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 78,404 KB
最終ジャッジ日時 2023-10-21 08:23:59
合計ジャッジ時間 3,004 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
65,980 KB
testcase_01 WA -
testcase_02 AC 43 ms
55,588 KB
testcase_03 AC 94 ms
77,544 KB
testcase_04 AC 148 ms
78,404 KB
testcase_05 AC 46 ms
61,360 KB
testcase_06 AC 43 ms
55,588 KB
testcase_07 AC 42 ms
55,588 KB
testcase_08 AC 42 ms
55,588 KB
testcase_09 AC 43 ms
55,588 KB
testcase_10 AC 42 ms
55,588 KB
testcase_11 AC 43 ms
55,588 KB
testcase_12 AC 43 ms
55,588 KB
testcase_13 AC 43 ms
55,588 KB
testcase_14 AC 43 ms
55,588 KB
testcase_15 AC 43 ms
55,588 KB
testcase_16 WA -
testcase_17 AC 44 ms
55,588 KB
testcase_18 AC 43 ms
55,588 KB
testcase_19 AC 43 ms
55,588 KB
testcase_20 WA -
testcase_21 AC 42 ms
55,588 KB
testcase_22 AC 48 ms
61,224 KB
testcase_23 AC 45 ms
61,360 KB
testcase_24 AC 47 ms
61,360 KB
testcase_25 AC 45 ms
61,360 KB
testcase_26 AC 44 ms
59,312 KB
testcase_27 AC 59 ms
66,620 KB
testcase_28 AC 46 ms
61,360 KB
testcase_29 AC 48 ms
63,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

w,h,*b = map(int,open(0).read().split())

M = 2**15
from collections import deque
q = deque()
d = {}
for i in [1,w]:
    if b[0] != b[i]:
        q.append(i*M)
        d[i*M] = 1

def check(c,x2,delta):
    if 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,x2,delta)
    if h2+1 < h: check(x2+w,x2,delta)
    if w2: check(x2-1,x2,delta)
    if w2+1 < w: check(x2+1,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