結果

問題 No.5020 Averaging
ユーザー ゆ
提出日時 2024-02-25 16:16:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 938 ms / 1,000 ms
コード長 2,468 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 81,976 KB
スコア 27,709,462
最終ジャッジ日時 2024-02-25 16:17:29
合計ジャッジ時間 49,884 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 937 ms
80,668 KB
testcase_01 AC 937 ms
79,660 KB
testcase_02 AC 937 ms
79,824 KB
testcase_03 AC 936 ms
80,032 KB
testcase_04 AC 937 ms
79,984 KB
testcase_05 AC 937 ms
80,260 KB
testcase_06 AC 937 ms
80,192 KB
testcase_07 AC 938 ms
79,932 KB
testcase_08 AC 937 ms
79,788 KB
testcase_09 AC 937 ms
80,720 KB
testcase_10 AC 938 ms
79,908 KB
testcase_11 AC 937 ms
80,048 KB
testcase_12 AC 937 ms
79,656 KB
testcase_13 AC 936 ms
79,592 KB
testcase_14 AC 937 ms
81,032 KB
testcase_15 AC 936 ms
79,744 KB
testcase_16 AC 937 ms
80,148 KB
testcase_17 AC 936 ms
79,688 KB
testcase_18 AC 938 ms
80,808 KB
testcase_19 AC 937 ms
80,100 KB
testcase_20 AC 937 ms
79,688 KB
testcase_21 AC 937 ms
79,964 KB
testcase_22 AC 937 ms
79,440 KB
testcase_23 AC 937 ms
79,848 KB
testcase_24 AC 937 ms
80,544 KB
testcase_25 AC 937 ms
79,832 KB
testcase_26 AC 937 ms
80,152 KB
testcase_27 AC 937 ms
79,776 KB
testcase_28 AC 937 ms
79,812 KB
testcase_29 AC 938 ms
79,748 KB
testcase_30 AC 937 ms
79,980 KB
testcase_31 AC 937 ms
80,128 KB
testcase_32 AC 937 ms
79,700 KB
testcase_33 AC 937 ms
79,432 KB
testcase_34 AC 937 ms
80,052 KB
testcase_35 AC 937 ms
79,528 KB
testcase_36 AC 937 ms
80,796 KB
testcase_37 AC 937 ms
80,104 KB
testcase_38 AC 936 ms
79,688 KB
testcase_39 AC 936 ms
79,796 KB
testcase_40 AC 937 ms
79,716 KB
testcase_41 AC 938 ms
79,560 KB
testcase_42 AC 937 ms
79,932 KB
testcase_43 AC 937 ms
79,776 KB
testcase_44 AC 936 ms
80,088 KB
testcase_45 AC 937 ms
80,364 KB
testcase_46 AC 937 ms
79,412 KB
testcase_47 AC 937 ms
79,492 KB
testcase_48 AC 936 ms
81,976 KB
testcase_49 AC 937 ms
79,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from time import time
start = time()
import sys
from random import randint,sample
from itertools import combinations
from collections import defaultdict
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,PREV):
  ABS = list()
  for v in range(1,N):
    na,nb = (A[0]+A[v])//2,(B[0]+B[v])//2
    if A[0]==A[v] and B[0]==B[v]: continue
    if PREV[(0,v)]==(na,nb): continue
    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,PREV): # 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
    if PREV[(u,v)]==(na,nb): continue
    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)
  flag = False
  PREV = defaultdict(tuple)
  while TURN<50:
    if time()-start>0.9: return
    if flag:
      u,v = sample(NUM,2)
      flag = False
    else:
      ABS = create_abs(A,B,V1,V2,PREV)
      if ABS[0][0]==0: # 頭打ちになったら1以外とマージする
        u,v = sample(NUM,2)
      elif A[0]==A[ABS[0][1]] and B[0]==B[ABS[0][1]]:
        u,v = sample(NUM,2)
      elif ABS[0][0]<0:
        u,v = sample(NUM,2)
      else:
        u,v = 0,ABS[0][1]
        flag = True
    ANS.append((u+1,v+1))
    na,nb = (A[u]+A[v])//2,(B[u]+B[v])//2
    if PREV[(u,v)]==(na,nb):
      while PREV[(u,v)]==(na,nb):
        u,v = sample(NUM,2)
        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
    PREV[(u,v)] = (na,nb)
    PREV[(v,u)] = (na,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