結果

問題 No.5020 Averaging
ユーザー ゆ
提出日時 2024-02-25 15:31:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 944 ms / 1,000 ms
コード長 2,330 bytes
コンパイル時間 221 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 80,032 KB
スコア 26,955,353
最終ジャッジ日時 2024-02-25 15:32:47
合計ジャッジ時間 49,917 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 938 ms
79,760 KB
testcase_01 AC 938 ms
79,644 KB
testcase_02 AC 938 ms
79,768 KB
testcase_03 AC 938 ms
80,032 KB
testcase_04 AC 937 ms
79,504 KB
testcase_05 AC 938 ms
79,512 KB
testcase_06 AC 937 ms
79,640 KB
testcase_07 AC 938 ms
79,384 KB
testcase_08 AC 938 ms
79,256 KB
testcase_09 AC 937 ms
79,392 KB
testcase_10 AC 938 ms
79,504 KB
testcase_11 AC 939 ms
79,512 KB
testcase_12 AC 937 ms
79,772 KB
testcase_13 AC 938 ms
79,504 KB
testcase_14 AC 936 ms
79,512 KB
testcase_15 AC 938 ms
79,520 KB
testcase_16 AC 938 ms
79,640 KB
testcase_17 AC 938 ms
79,768 KB
testcase_18 AC 938 ms
79,768 KB
testcase_19 AC 939 ms
79,768 KB
testcase_20 AC 938 ms
79,776 KB
testcase_21 AC 942 ms
79,760 KB
testcase_22 AC 937 ms
79,392 KB
testcase_23 AC 938 ms
79,388 KB
testcase_24 AC 938 ms
79,768 KB
testcase_25 AC 938 ms
79,640 KB
testcase_26 AC 940 ms
79,768 KB
testcase_27 AC 942 ms
79,380 KB
testcase_28 AC 942 ms
79,896 KB
testcase_29 AC 939 ms
79,888 KB
testcase_30 AC 937 ms
79,904 KB
testcase_31 AC 937 ms
79,392 KB
testcase_32 AC 938 ms
79,236 KB
testcase_33 AC 938 ms
80,032 KB
testcase_34 AC 937 ms
79,632 KB
testcase_35 AC 939 ms
79,640 KB
testcase_36 AC 938 ms
79,768 KB
testcase_37 AC 938 ms
80,024 KB
testcase_38 AC 937 ms
79,512 KB
testcase_39 AC 938 ms
79,376 KB
testcase_40 AC 937 ms
79,648 KB
testcase_41 AC 938 ms
79,760 KB
testcase_42 AC 939 ms
79,508 KB
testcase_43 AC 938 ms
79,768 KB
testcase_44 AC 936 ms
79,640 KB
testcase_45 AC 937 ms
79,896 KB
testcase_46 AC 938 ms
79,760 KB
testcase_47 AC 942 ms
79,896 KB
testcase_48 AC 938 ms
79,896 KB
testcase_49 AC 944 ms
79,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from time import time
start = time()
import sys
from random import randint
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 = other_merge(A,B,PREV)
      flag = False
    else:
      ABS = create_abs(A,B,V1,V2,PREV)
      if ABS[0][0]==0: # 頭打ちになったら1以外とマージする
        u,v = other_merge(A,B,PREV)
      elif A[0]==A[ABS[0][1]] and B[0]==B[ABS[0][1]]:
        u,v = other_merge(A,B,PREV)
      elif ABS[0][0]<0:
        u,v = other_merge(A,B,PREV)
      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 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)
    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