結果

問題 No.5020 Averaging
ユーザー titia
提出日時 2024-02-25 16:34:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 949 ms / 1,000 ms
コード長 2,315 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 89,108 KB
スコア 27,810,889
最終ジャッジ日時 2024-02-25 16:36:11
合計ジャッジ時間 50,447 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

from random import randint
from time import time

time0=time()

N=int(input())
A=[list(map(int,input().split())) for i in range(N)]

A_INI=[]
for a,b in A:
    A_INI.append([a,b])

LANS=[]
score=10**18

while time()-time0<0.9:
    ANS=[]
    A=[]
    for a,b in A_INI:
        A.append([a,b])

    for i in range(49):
        while True:
            x,y=randint(0,N-1),randint(0,N-1)

            if x==y:
                continue
            else:
                break

        c=(A[x][0]+A[y][0])//2
        d=(A[x][1]+A[y][1])//2

        A[x][0]=A[y][0]=c
        A[x][1]=A[y][1]=d

        ANS.append(x)
        ANS.append(y)

        if x!=0:

            c0=(A[0][0]+A[x][0])//2
            d0=(A[0][1]+A[x][1])//2

            if max(abs(5*(10**17)-c0),abs(5*(10**17)-d0))<score:
                score=max(abs(5*(10**17)-c0),abs(5*(10**17)-d0))
                LANS=ANS[:]+[0]+[x]

            if y!=0 and len(ANS)<48:
            
                c1=(c0+A[y][0])//2
                d1=(d0+A[y][1])//2

                if max(abs(5*(10**17)-c1),abs(5*(10**17)-d1))<score:
                    score=max(abs(5*(10**17)-c1),abs(5*(10**17)-d1))
                    LANS=ANS[:]+[0]+[x]+[0]+[y]

        if y!=0:
        
            c0=(A[0][0]+A[y][0])//2
            d0=(A[0][1]+A[y][1])//2

            if max(abs(5*(10**17)-c0),abs(5*(10**17)-d0))<score:
                score=max(abs(5*(10**17)-c0),abs(5*(10**17)-d0))
                LANS=ANS[:]+[0]+[y]

            if x!=0 and len(ANS)<48:
            
                c1=(c0+A[x][0])//2
                d1=(d0+A[x][1])//2

                if max(abs(5*(10**17)-c1),abs(5*(10**17)-d1))<score:
                    score=max(abs(5*(10**17)-c1),abs(5*(10**17)-d1))
                    LANS=ANS[:]+[0]+[y]+[0]+[x]

        if x!=0 and y!=0 and len(ANS)<48:
            c0=(A[x][0]+A[y][0])//2
            d0=(A[x][1]+A[y][1])//2

            c1=(c0+A[0][0])//2
            d1=(d0+A[0][1])//2

            if max(abs(5*(10**17)-c1),abs(5*(10**17)-d1))<score:
                score=max(abs(5*(10**17)-c1),abs(5*(10**17)-d1))
                LANS=ANS[:]+[x]+[y]+[0]+[x]
            

print(len(LANS)//2)
for i in range(0,len(LANS),2):
    print(LANS[i]+1,LANS[i+1]+1)
            
        


        
        
    
    

0