結果

問題 No.2743 Twisted Lattice
ユーザー tassei903tassei903
提出日時 2024-04-13 02:06:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,867 ms / 3,000 ms
コード長 1,045 bytes
コンパイル時間 574 ms
コンパイル使用メモリ 82,416 KB
実行使用メモリ 364,568 KB
最終ジャッジ日時 2024-04-13 02:07:08
合計ジャッジ時間 17,641 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,791 ms
364,452 KB
testcase_01 AC 1,053 ms
157,336 KB
testcase_02 AC 1,067 ms
158,360 KB
testcase_03 AC 1,834 ms
364,568 KB
testcase_04 AC 1,829 ms
357,884 KB
testcase_05 AC 1,816 ms
358,440 KB
testcase_06 AC 1,867 ms
358,288 KB
testcase_07 AC 1,843 ms
358,796 KB
testcase_08 AC 40 ms
53,864 KB
testcase_09 AC 40 ms
55,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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])
0