結果

問題 No.5020 Averaging
ユーザー utauta
提出日時 2024-02-25 13:53:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 3,571 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 81,324 KB
スコア 25,906,905
最終ジャッジ日時 2024-02-25 13:54:02
合計ジャッジ時間 8,098 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

from dataclasses import dataclass, field
# from sortedcontainers import SortedList, SortedDict, SortedSet
from random import random, seed, randrange, choice, sample
# from itertools import permutations, combinations, product
from collections import deque, defaultdict, Counter
# from heapq import heapify, heappush, heappop
# from bisect import bisect_right, bisect_left
from time import time
import sys
sys.setrecursionlimit(1000000)
seed(0)

def input():
    return sys.stdin.buffer.readline().rstrip().decode(encoding='utf-8')
try:    isLocal
except: isLocal = False
if isLocal: input = line

def randrange_s(stop:int)->int: return int(random()*stop)
def randrange_ss(start:int, stop:int)->int: return int(random()*(stop-start)+start)

class AHC():
    def __init__(self):
        self.sTime = time()
        self.get_input()
        self.preprocessing()

    def get_input(self):
        self.N = int(input())
        AB = [list(map(int, input().split())) for _ in range(self.N)]
        self.A, self.B = [], []
        for a, b in AB:
            self.A.append(float(a))
            self.B.append(float(b))
        return

    def preprocessing(self):
        self.target = float(5*10**17)
        return 

    def get_score(self):
        return max(abs(self.target-self.A[0]), abs(self.target-self.B[0]))

    def get_score2(self, a, b):
        return max(abs(self.target-a), abs(self.target-b))

    def greedy(self):
        self.ans = []
        self.hist = []
        self.cur = self.get_score()
        self.cnt = 0
        self.eTime = self.sTime+0.9
        while self.cnt<50 and time()<self.eTime:
            while self.cnt<50 and time()<self.eTime:
                # カード1と作用させる
                evaList = []
                for i in range(1, self.N):
                    a = (self.A[0]+self.A[i])/2
                    b = (self.B[0]+self.B[i])/2
                    evaList.append([self.get_score2(a, b), i])
                nxt, v = min(evaList)
                if nxt>=self.cur: break
                self.hist = []
                self.cnt += 1
                self.cur = nxt
                self.ans.append(f"1 {v+1}")
                mean = (self.A[0]+self.A[v])/2
                self.A[0] = mean
                self.A[v] = mean
                mean = (self.B[0]+self.B[v])/2
                self.B[0] = mean
                self.B[v] = mean

            # カード1を理想の状態にするためのカード作り
            target_A = self.target-self.A[0]+self.target
            target_B = self.target-self.B[0]+self.target
            evaList = []
            for u in range(1, self.N-1):
                for v in range(u+1, self.N):
                    if self.A[u]==self.A[v] and self.B[u]==self.B[v]: continue
                    if f"{u+1} {v+1}" in self.hist: continue
                    a = (self.A[u]+self.A[v])/2
                    b = (self.B[u]+self.B[v])/2
                    evaList.append([(target_A-a)**2+(target_B-b)**2, u, v])
            if len(evaList)==0: break
            _, u, v = min(evaList)
            self.cnt += 1
            self.ans.append(f"{u+1} {v+1}")
            self.hist.append(f"{u+1} {v+1}")
            mean = (self.A[u]+self.A[v])/2
            self.A[u] = mean
            self.A[v] = mean
            mean = (self.B[u]+self.B[v])/2
            self.B[u] = mean
            self.B[v] = mean
        return

    def update(self):
        pass
    
    def output(self):
        print(len(self.ans))
        print("\n".join(self.ans))

ahc = AHC()
ahc.greedy()
ahc.output()
0