結果

問題 No.5020 Averaging
ユーザー ゆ
提出日時 2024-02-25 14:23:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 937 ms / 1,000 ms
コード長 1,877 bytes
コンパイル時間 449 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 79,532 KB
スコア 23,112,249
最終ジャッジ日時 2024-02-25 14:24:33
合計ジャッジ時間 48,228 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 893 ms
79,028 KB
testcase_01 AC 896 ms
79,144 KB
testcase_02 AC 892 ms
79,008 KB
testcase_03 AC 895 ms
78,860 KB
testcase_04 AC 907 ms
78,996 KB
testcase_05 AC 902 ms
78,628 KB
testcase_06 AC 891 ms
78,644 KB
testcase_07 AC 908 ms
78,940 KB
testcase_08 AC 901 ms
78,948 KB
testcase_09 AC 909 ms
78,920 KB
testcase_10 AC 899 ms
78,940 KB
testcase_11 AC 892 ms
78,800 KB
testcase_12 AC 890 ms
78,792 KB
testcase_13 AC 897 ms
78,900 KB
testcase_14 AC 911 ms
78,808 KB
testcase_15 AC 893 ms
78,952 KB
testcase_16 AC 898 ms
79,184 KB
testcase_17 AC 891 ms
78,728 KB
testcase_18 AC 893 ms
79,052 KB
testcase_19 AC 892 ms
78,940 KB
testcase_20 AC 904 ms
79,196 KB
testcase_21 AC 891 ms
78,928 KB
testcase_22 AC 888 ms
78,932 KB
testcase_23 AC 899 ms
78,840 KB
testcase_24 AC 913 ms
78,544 KB
testcase_25 AC 900 ms
78,900 KB
testcase_26 AC 907 ms
78,796 KB
testcase_27 AC 888 ms
78,776 KB
testcase_28 AC 900 ms
79,420 KB
testcase_29 AC 906 ms
78,824 KB
testcase_30 AC 899 ms
79,532 KB
testcase_31 AC 890 ms
79,132 KB
testcase_32 AC 892 ms
79,312 KB
testcase_33 AC 900 ms
78,472 KB
testcase_34 AC 897 ms
78,780 KB
testcase_35 AC 887 ms
78,764 KB
testcase_36 AC 889 ms
78,904 KB
testcase_37 AC 899 ms
78,904 KB
testcase_38 AC 906 ms
79,456 KB
testcase_39 AC 901 ms
78,656 KB
testcase_40 AC 897 ms
79,208 KB
testcase_41 AC 904 ms
79,164 KB
testcase_42 AC 891 ms
78,780 KB
testcase_43 AC 888 ms
79,136 KB
testcase_44 AC 909 ms
78,872 KB
testcase_45 AC 888 ms
78,844 KB
testcase_46 AC 937 ms
79,020 KB
testcase_47 AC 898 ms
78,844 KB
testcase_48 AC 894 ms
78,968 KB
testcase_49 AC 910 ms
79,032 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,i])
  B.append([b,i])
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][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(A,B): # 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()
  ind = randint(0,2)
  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][0]-STAND),abs(B[0][0]-STAND)
  while TURN<50:
    if time()-start>2.85: return
    ABS = create_abs(A,B,V1,V2)
    if ABS[0][0]==0: # 頭打ちになったら1以外とマージする
      u,v = other_merge(A,B)
    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
    
  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.85:
  AA = [a[:] for a in A]
  BB = [b[:] for b in B]
  play(AA,BB)

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