結果
| 問題 |
No.124 門松列(3)
|
| コンテスト | |
| ユーザー |
convexineq
|
| 提出日時 | 2020-12-18 21:44:37 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 706 bytes |
| コンパイル時間 | 172 ms |
| コンパイル使用メモリ | 82,592 KB |
| 実行使用メモリ | 78,680 KB |
| 最終ジャッジ日時 | 2024-09-21 09:26:02 |
| 合計ジャッジ時間 | 2,826 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 23 WA * 3 |
ソースコード
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)
convexineq