結果

問題 No.5020 Averaging
ユーザー ゆ
提出日時 2024-02-25 15:19:38
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,141 bytes
コンパイル時間 308 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 78,652 KB
スコア 0
最終ジャッジ日時 2024-02-25 15:20:28
合計ジャッジ時間 50,045 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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)
  flag = False
  while TURN<50:
    if time()-start>0.9: return
    if flag:
      u,v = other_merge(A,B)
      flag = False
    else:
      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]
        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
      #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)

cnt = 0
while time()-start<0.9:
  AA = A[:]
  BB = B[:]
  play(AA,BB)
  cnt += 1
print(cnt)

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