結果
| 問題 | No.124 門松列(3) |
| コンテスト | |
| ユーザー |
convexineq
|
| 提出日時 | 2020-12-18 21:48:48 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 95 ms / 5,000 ms |
| コード長 | 675 bytes |
| コンパイル時間 | 314 ms |
| コンパイル使用メモリ | 82,132 KB |
| 実行使用メモリ | 76,844 KB |
| 最終ジャッジ日時 | 2024-09-21 09:26:11 |
| 合計ジャッジ時間 | 2,726 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
ソースコード
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)
convexineq