結果

問題 No.5020 Averaging
ユーザー YuuuTYuuuT
提出日時 2024-02-25 15:01:18
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,913 bytes
コンパイル時間 338 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 93,472 KB
スコア 0
最終ジャッジ日時 2024-02-25 15:01:29
合計ジャッジ時間 4,804 ms
ジャッジサーバーID
(参考情報)
judge10 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from time import time
start = time()
import sys
from random import randint
from itertools import combinations
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def ms(): return map(int, input().split())
def li(): return list(map(int,input().split()))
# ////////////////////////////////
N = ii()
A = list()
B = list()
for i in range(N):
  a,b = ms()
  A.append(a)
  B.append(b)
NUM = [i for i in range(2,N)]
STAND = 5*pow(10,17)

def create_abs(A,B,V1,V2):
  ABS = list()
  for v in range(1,N):
    na,nb = (A[0]+A[v])//2,(B[0]+B[v])//2
    n1,n2 = abs(na-STAND),abs(nb-STAND)
    tmp = max(V1,V2)-max(n1,n2)
    ABS.append((tmp,v))
  ABS.sort(reverse=True)
  return ABS

def other_merge(A,B): # STANDにできるだけ近いやつを作る
  CAND = list()
  for (u,v) in combinations(NUM,2):
    if A[u]==A[v] and B[u]==B[v]: continue
    na,nb = (A[u]+A[v])//2,(B[u]+B[v])//2
    n1,n2 = abs(na-STAND),abs(nb-STAND)
    CAND.append((max(n1,n2),u,v))
  CAND.sort()
  ind = randint(0,5)
  u,v = CAND[ind][1],CAND[ind][2]
  return u,v

def play(A,B):
  global MAXV,BEST_ANS
  TURN = 0
  ANS = list()
  V1,V2 = abs(A[0]-STAND),abs(B[0]-STAND)
  while TURN<50:
    if time()-start>2.85: return
    ABS = create_abs(A,B,V1,V2)
    if ABS[0][0]==0: # 頭打ちになったら1以外とマージする
      u,v = other_merge(A,B)
    elif A[0]==A[ABS[0][1]] and B[0]==B[ABS[0][1]]:
      u,v = other_merge(A,B)
    else:
      u,v = 0,ABS[0][1]
    ANS.append((u+1,v+1))
    na,nb = (A[u]+A[v])//2,(B[u]+B[v])//2
    if u==0:
      n1,n2 = abs(na-STAND),abs(nb-STAND)
      V1,V2 = n1,n2
    A[u],A[v],B[u],B[v] = na,na,nb,nb
    TURN += 1
    
  if MAXV>max(V1,V2):
    MAXV = max(V1,V2)
    BEST_ANS = [a[:] for a in ANS]
    return

BEST_ANS = list()
MAXV = pow(10,18)

while time()-start<2.85:
  AA = A[:]
  BB = B[:]
  play(AA,BB)

print(len(BEST_ANS))
for u,v in BEST_ANS: print(u,v)
0