結果

問題 No.3438 [Cherry 8th Tune D] 競プロは向いてない
コンテスト
ユーザー LyricalMaestro
提出日時 2026-08-12 00:02:31
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 3,542 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 227 ms
コンパイル使用メモリ 96,108 KB
実行使用メモリ 146,320 KB
最終ジャッジ日時 2026-08-12 00:03:19
合計ジャッジ時間 42,552 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other WA * 31 RE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# https://yukicoder.me/problems/no/3438

from collections import deque
BORDER = 2 * 10 ** 9

DIRECTIONS = []
for i in range(-1, 2):
    for j in range(-1, 2):
        DIRECTIONS.append((i, j))

def solve(N, xy):
    xy_array = [(xy[i][0], xy[i][1], i) for i in range(N)]

    # 上半平面について解く
    xy_array.sort(key=lambda x: (x[0], x[1]))

    stack = deque()
    x0, y0, index0 = xy_array[0]
    x1, y1, index1 = xy_array[1]
    stack.append((x0, y0, index0, (1, 0)))
    stack.append((x1, y1, index1, (y1- y0, x1 - x0)))
    for i in range(2, N):
        new_x, new_y, new_index = xy_array[i]
        while len(stack) >= 1:
            x, y, _, coef = stack[-1]

            new_coef = (new_y - y, new_x - x)
            if new_coef[0] * coef[1] >= coef[0] * new_coef[1]:
                stack.pop()
            else:
                stack.append((new_x, new_y, new_index, new_coef))
                break
    upper_array = list(stack)

    # 下半平面
    xy_array.sort(key=lambda x: (x[0], x[1]), reverse=True)
    stack = deque()
    x0, y0, index0 = xy_array[0]
    x1, y1, index1 = xy_array[1]
    stack.append((x0, y0, index0, (1, 0)))
    stack.append((x1, y1, index1, (y0- y1, x0 - x1)))
    for i in range(2, N):
        new_x, new_y, new_index = xy_array[i]
        while len(stack) >= 1:
            x, y, _, coef = stack[-1]

            new_coef = (y - new_y, x - new_x)
            if new_coef[0] * coef[1] >= coef[0] * new_coef[1]:
                stack.pop()
            else:
                stack.append((new_x, new_y, new_index, new_coef))
                break
    lower_array = list(stack)

    surround_array = []
    prev_index = -1
    for i in range(len(upper_array)):
        if prev_index != upper_array[i][2]:
            surround_array.append(upper_array[i][2])
        prev_index = upper_array[i][2]
    for i in range(len(lower_array)):
        if prev_index != lower_array[i][2]:
            surround_array.append(lower_array[i][2])
        prev_index = lower_array[i][2]
    if surround_array[0] == surround_array[-1]:
        surround_array.pop()

    answer = ["No"] * N
    for i in range(len(surround_array)):
        prev_index = surround_array[(i - 1) % len(surround_array)]
        current_index = surround_array[i]
        next_index = surround_array[(i + 1) % len(surround_array)]

        x1, y1 = xy[prev_index]
        x0, y0 = xy[current_index]
        x2, y2 = xy[next_index]

        diff_y = y0 - y1
        while abs(diff_y) > 0 and abs(diff_y) % 2 == 0:
            diff_y //= 2

        diff_x = x0 - x1
        while abs(diff_x) > 0 and abs(diff_x) % 2 == 0:
            diff_x //= 2

        for dx, dy in DIRECTIONS:
            new_diff_x = diff_x + dx
            new_diff_y = diff_y + dy
            if -BORDER <= new_diff_x <= BORDER and -BORDER <= new_diff_y <= BORDER:
                if (new_diff_x * (y1 - y0)) - (new_diff_y * (x1 - x0)) < 0 and (new_diff_x * (y2 - y0)) - (new_diff_y * (x2 - x0)) < 0:
                    vec = [-new_diff_y, new_diff_x]
                    answer[current_index] = " ".join(map(str, vec))
                    break
    return answer

def main():
    T = int(input())
    answers = []
    for _ in range(T):
        N = int(input())
        xy = []
        for _ in range(N):
            x, y = map(int ,input().split())
            xy.append((x, y))
        ans = solve(N, xy)
        answers.append(ans)
        
    for ans in answers:
        for a in ans:
            print(a)






if __name__ == "__main__":
    main()
0