結果

問題 No.5020 Averaging
ユーザー judgelawjudgelaw
提出日時 2024-02-25 14:17:45
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,981 bytes
コンパイル時間 250 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 84,520 KB
スコア 498,740
最終ジャッジ日時 2024-02-25 14:18:33
合計ジャッジ時間 48,257 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 RE -
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 RE -
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
st=time()

import sys
input = lambda: sys.stdin.readline().rstrip()
from math import log10
from copy import copy,deepcopy
from random import randint,random,choice
from bisect import bisect,bisect_left,insort

MAX_OP=50
TIME_LIMIT=0.9
TARGET_NUM=5*10**17

# カード1のスコアだけ見ればいいのか
# 奇数回目の操作でカード1以外を操作する
# 偶数回目でカード1を操作する

# カード1のスコアを計算

def calc_front(AB):return abs(AB[0][0]-TARGET_NUM)

def calc_back(AB):return abs(AB[0][1]-TARGET_NUM)

def calc_Score(cnt,AB):
    V1=calc_front(AB)
    V2=calc_front(AB)
    
    temp=max(V1,V2)

    if temp==0:return 2000050-cnt
    return int(2000000-100000*log10(temp+1))

def rewrite_front(u,v):
    temp=(tempAB[u][0]+tempAB[v][0])//2
    tempAB[u][0]=temp
    tempAB[v][0]=temp

def rewrite_back(u,v):
    temp=(tempAB[u][1]+tempAB[v][1])//2
    tempAB[u][1]=temp
    tempAB[v][1]=temp


N=int(input())
AB=[list(map(int, input().split()))  for _ in range(N)]


NowScore=calc_Score(0,AB)
UV=[]
premove=-1
preop=-1

while time()-st<=TIME_LIMIT:

    tempAB=deepcopy(AB)    
    tempUV=[]
    pretempScore=0
    opcnt=randint(0,MAX_OP)

    for cnt in range(1,opcnt+1):

        # 各カード表裏について値を記録する
        F_set=[]
        B_set=[]

        for i in range(1,N):

            a,b=tempAB[i]
            insort(F_set,(a,i))
            insort(B_set,(b,i))

        if cnt&1:

            F,B=tempAB[0]

            # 表裏を適当に書き換える
            k=randint(0,1)
            preop=k
            if k:
                while 1:
                    a,u=choice(F_set)
                    bk=bisect_left(F_set,(2*TARGET_NUM-a,0))
                    if bk>=N-1:bk=N-2

                    b,v=F_set[bk]
                    if u!=v:break
                
                rewrite_front(u,v)


            else:
                while 1:
                    c,u=choice(B_set)
                    dk=bisect_left(B_set,(2*TARGET_NUM-c,0))
                    if dk>=N-1:dk=N-2

                    d,v=B_set[dk]
                    if u!=v:break

                rewrite_back(u,v)

            tempUV.append((u,v))
            premove=u


        else:
            k=randint(0,1)

            if k:

                a=tempAB[0][0]
                bk=bisect_left(F_set,(2*TARGET_NUM-a,0))
                if bk>=N-1:bk=N-2

                b,v=F_set[bk]
                rewrite_front(0,v)
            else:

                c=tempAB[0][1]
                dk=bisect_left(B_set,(2*TARGET_NUM-c,0))
                if dk>=N-1:dk=N-2

                d,v=B_set[dk]

                rewrite_back(0,v)

            tempScore=calc_Score(cnt,tempAB)
            if pretempScore>tempScore:break

            pretempScore=tempScore
            tempUV.append((0,v))

    if tempScore>NowScore:
        NowScore=tempScore
        UV=deepcopy(tempUV)


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