結果

問題 No.5020 Averaging
ユーザー ゆ
提出日時 2024-02-25 15:11:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 939 ms / 1,000 ms
コード長 1,987 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 78,404 KB
スコア 27,235,463
最終ジャッジ日時 2024-02-25 15:12:13
合計ジャッジ時間 49,755 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 936 ms
78,208 KB
testcase_01 AC 937 ms
78,264 KB
testcase_02 AC 937 ms
78,144 KB
testcase_03 AC 938 ms
78,236 KB
testcase_04 AC 939 ms
77,956 KB
testcase_05 AC 937 ms
77,960 KB
testcase_06 AC 937 ms
78,064 KB
testcase_07 AC 938 ms
78,000 KB
testcase_08 AC 937 ms
78,404 KB
testcase_09 AC 936 ms
78,156 KB
testcase_10 AC 937 ms
77,900 KB
testcase_11 AC 938 ms
78,080 KB
testcase_12 AC 937 ms
77,872 KB
testcase_13 AC 938 ms
77,876 KB
testcase_14 AC 937 ms
78,032 KB
testcase_15 AC 937 ms
78,004 KB
testcase_16 AC 937 ms
78,264 KB
testcase_17 AC 937 ms
78,076 KB
testcase_18 AC 937 ms
78,100 KB
testcase_19 AC 936 ms
78,268 KB
testcase_20 AC 936 ms
78,264 KB
testcase_21 AC 938 ms
78,188 KB
testcase_22 AC 938 ms
78,272 KB
testcase_23 AC 936 ms
78,196 KB
testcase_24 AC 937 ms
77,992 KB
testcase_25 AC 938 ms
78,152 KB
testcase_26 AC 938 ms
77,980 KB
testcase_27 AC 937 ms
78,008 KB
testcase_28 AC 937 ms
78,136 KB
testcase_29 AC 939 ms
77,828 KB
testcase_30 AC 937 ms
78,144 KB
testcase_31 AC 937 ms
77,992 KB
testcase_32 AC 937 ms
77,736 KB
testcase_33 AC 937 ms
78,120 KB
testcase_34 AC 938 ms
78,252 KB
testcase_35 AC 938 ms
78,216 KB
testcase_36 AC 937 ms
78,180 KB
testcase_37 AC 938 ms
77,952 KB
testcase_38 AC 938 ms
78,296 KB
testcase_39 AC 938 ms
78,164 KB
testcase_40 AC 937 ms
78,332 KB
testcase_41 AC 937 ms
78,120 KB
testcase_42 AC 939 ms
78,120 KB
testcase_43 AC 937 ms
77,864 KB
testcase_44 AC 938 ms
78,152 KB
testcase_45 AC 938 ms
78,196 KB
testcase_46 AC 937 ms
77,892 KB
testcase_47 AC 938 ms
78,236 KB
testcase_48 AC 937 ms
78,160 KB
testcase_49 AC 938 ms
78,096 KB
権限があれば一括ダウンロードができます

ソースコード

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>0.9: 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)
    elif ABS[0][0]<0:
      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
      #print(max(V1,V2))
    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<0.9:
  AA = A[:]
  BB = B[:]
  play(AA,BB)

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