結果

問題 No.5020 Averaging
ユーザー ゆ
提出日時 2024-02-25 14:02:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 165 ms / 1,000 ms
コード長 1,809 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 77,380 KB
スコア 21,197,878
最終ジャッジ日時 2024-02-25 14:02:47
合計ジャッジ時間 8,439 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
77,132 KB
testcase_01 AC 141 ms
77,132 KB
testcase_02 AC 112 ms
77,260 KB
testcase_03 AC 112 ms
77,004 KB
testcase_04 AC 113 ms
77,252 KB
testcase_05 AC 137 ms
77,132 KB
testcase_06 AC 165 ms
77,260 KB
testcase_07 AC 114 ms
77,132 KB
testcase_08 AC 114 ms
77,132 KB
testcase_09 AC 115 ms
77,132 KB
testcase_10 AC 111 ms
77,132 KB
testcase_11 AC 117 ms
77,132 KB
testcase_12 AC 137 ms
77,132 KB
testcase_13 AC 109 ms
77,252 KB
testcase_14 AC 134 ms
77,368 KB
testcase_15 AC 115 ms
77,132 KB
testcase_16 AC 111 ms
77,240 KB
testcase_17 AC 114 ms
77,368 KB
testcase_18 AC 116 ms
77,260 KB
testcase_19 AC 115 ms
77,256 KB
testcase_20 AC 118 ms
77,260 KB
testcase_21 AC 112 ms
77,260 KB
testcase_22 AC 113 ms
77,112 KB
testcase_23 AC 137 ms
77,132 KB
testcase_24 AC 115 ms
77,260 KB
testcase_25 AC 139 ms
77,132 KB
testcase_26 AC 116 ms
77,260 KB
testcase_27 AC 109 ms
77,252 KB
testcase_28 AC 112 ms
77,260 KB
testcase_29 AC 135 ms
77,260 KB
testcase_30 AC 116 ms
77,112 KB
testcase_31 AC 113 ms
77,132 KB
testcase_32 AC 118 ms
77,240 KB
testcase_33 AC 141 ms
77,132 KB
testcase_34 AC 116 ms
77,124 KB
testcase_35 AC 118 ms
77,260 KB
testcase_36 AC 109 ms
77,132 KB
testcase_37 AC 112 ms
77,380 KB
testcase_38 AC 114 ms
77,260 KB
testcase_39 AC 112 ms
77,260 KB
testcase_40 AC 120 ms
77,240 KB
testcase_41 AC 113 ms
77,240 KB
testcase_42 AC 112 ms
77,260 KB
testcase_43 AC 113 ms
77,268 KB
testcase_44 AC 116 ms
77,132 KB
testcase_45 AC 114 ms
77,132 KB
testcase_46 AC 113 ms
77,240 KB
testcase_47 AC 117 ms
77,132 KB
testcase_48 AC 117 ms
77,260 KB
testcase_49 AC 138 ms
77,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from time import time
start = time()
import sys,math
if len(sys.argv) == 2: sys.stdin = open(sys.argv[1])
from random import randint,randrange,sample,shuffle,choice
from collections import defaultdict,deque
from itertools import combinations,permutations,accumulate,product
from bisect import bisect,bisect_left,bisect_right
from heapq import heappop,heappush,heapify
from copy import deepcopy
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,i])
  B.append([b,i])
NUM = [i for i in range(2,N)]
STAND = 5*pow(10,17)
TURN = 0
V1,V2 = abs(A[0][0]-STAND),abs(B[0][0]-STAND)
def create_abs():
  ABS = list()
  for v in range(1,N):
    na,nb = (A[0][0]+A[v][0])//2,(B[0][0]+B[v][0])//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(): # STANDにできるだけ近いやつを作る
  CAND = list()
  for (u,v) in combinations(NUM,2):
    na,nb = (A[u][0]+A[v][0])//2,(B[u][0]+B[v][0])//2
    n1,n2 = abs(na-STAND),abs(nb-STAND)
    CAND.append((max(n1,n2),u,v))
  CAND.sort()
  u,v = CAND[0][1],CAND[0][2]
  return u,v


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