結果

問題 No.2743 Twisted Lattice
コンテスト
ユーザー flippergo
提出日時 2026-07-23 20:27:14
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 558 ms / 3,000 ms
+ 785µs
コード長 1,112 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 584 ms
コンパイル使用メモリ 95,980 KB
実行使用メモリ 170,832 KB
最終ジャッジ日時 2026-07-23 20:27:39
合計ジャッジ時間 7,003 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from bisect import bisect_left
H,W,N = map(int,input().split())
A = []
B = {}
INFTY = 10**10
for _ in range(N):
    y,x = map(int,input().split())
    A.append((y,x))
    if x not in B:
        B[x] = []
    B[x].append(y)
for x in B:
    B[x] = [-INFTY]+sorted(B[x])+[INFTY]
C1 = sorted(list(B.keys()))
C = [-INFTY]+C1+[INFTY]
D = [B[x][1]-x for x in C1]
Dmin = D[:]
for i in range(1,len(D)):
    Dmin[i] = min(Dmin[i-1],D[i])
Dmin = [INFTY]+Dmin+[INFTY]
E = [B[x][1]+x for x in C1]
Emin = E[:]
for i in range(len(E)-2,-1,-1):
    Emin[i] = min(Emin[i+1],E[i])
Emin = [INFTY]+Emin+[INFTY]
for i in range(N):
    y,x = A[i]
    ans = INFTY
    ind = bisect_left(B[x],y)
    ans = min(ans,y-B[x][ind-1],B[x][ind+1]-y)
    ind = bisect_left(C,x)
    if C[ind-1]+1==x:
        ans = min(ans,max(y,B[C[ind-1]][1]))
    if C[ind+1]==x+1:
        ans = min(ans,max(y,B[C[ind+1]][1]))
    if C[ind-1]==x-1:
        indL = ind-2
    else:
        indL = ind-1
    ans = min(ans,Dmin[indL]+x+y-2)
    if C[ind+1]==x+1:
        indR = ind+2
    else:
        indR = ind+1
    ans = min(ans,Emin[indR]+y-x-2)
    print(ans)
0