結果

問題 No.3074 Divide Points Fairly
ユーザー SPD_9X2
提出日時 2025-03-28 21:37:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 243 ms / 2,000 ms
コード長 974 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 82,704 KB
実行使用メモリ 84,096 KB
最終ジャッジ日時 2025-03-28 21:38:00
合計ジャッジ時間 9,359 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import random

N = int(input())

xy = []

for i in range(2*N):

    x,y = map(int,input().split())
    xy.append( (x,y) )

while True:

    a = 1
    b = random.randint(90000,10**5)
    if random.randint(0,1) == 0:
        b *= -1
    if random.randint(0,1) == 0:
        a,b = b,a

    l = -2*(10**10)
    r =  2*(10**10)+1

    while r-l != 1:

        m = (l+r)//2

        plus = 0
        minus = 0
        for x,y in xy:
            s = a*x+b*y+m
            if s < 0:
                minus += 1
            elif s > 0:
                plus += 1

        if plus > minus:
            r = m
        else:
            l = m

    for m in range(l-3,r+4):
        plus = 0
        minus = 0
        for x,y in xy:
            s = a*x+b*y+m
            if s < 0:
                minus += 1
            elif s > 0:
                plus += 1

        if plus == minus == N:
            print (a,b,m)
            sys.exit()

    # print (a,b,m)
    # assert False
0