結果
| 問題 |
No.2743 Twisted Lattice
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-13 02:06:50 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,628 ms / 3,000 ms |
| コード長 | 1,045 bytes |
| コンパイル時間 | 196 ms |
| コンパイル使用メモリ | 81,964 KB |
| 実行使用メモリ | 363,808 KB |
| 最終ジャッジ日時 | 2024-10-02 23:55:30 |
| 合計ジャッジ時間 | 15,190 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 8 |
ソースコード
inf = 10**18
H, W, N = map(int, input().split())
A, B = zip(*[map(int, input().split()) for _ in range(N)])
from collections import defaultdict
c = defaultdict(list)
for i in range(N):
c[B[i]].append((A[i], i))
s = set()
for x in c.keys():
s.add(x)
s.add(x-1)
s.add(x+1)
s.add(x-2)
s.add(x+2)
s = sorted(s)
ans = [inf] * N
z = inf
for y in s:
c[y].sort()
for x, i in c[y-2]:
z = min(z, x - y + 2)
for j in range(len(c[y])):
x, i = c[y][j]
if j:
ans[i] = min(ans[i], x - c[y][j-1][0])
if j+1 < len(c[y]):
ans[i] = min(ans[i], c[y][j+1][0] - x)
if c[y-1]:
ans[i] = min(ans[i], max(x, c[y-1][0][0]))
ans[i] = min(ans[i], z + x + y - 2)
z = inf
for y in s[::-1]:
for x, i in c[y+2]:
z = min(z, x + y + 2)
for j in range(len(c[y])):
x, i = c[y][j]
if c[y+1]:
ans[i] = min(ans[i], max(x, c[y+1][0][0]))
ans[i] = min(ans[i], z + x - y - 2)
for i in range(N):
print(ans[i])