結果

問題 No.5020 Averaging
ユーザー kumk
提出日時 2024-02-25 14:16:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 65 ms / 1,000 ms
コード長 1,892 bytes
コンパイル時間 241 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 68,988 KB
スコア 20,508,419
最終ジャッジ日時 2024-02-25 14:16:19
合計ジャッジ時間 5,310 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math

import io
import sys
import random
TARGET = 5*(10**17)

def cal_score(v1, v2, isDisplay = False):
    error1 = abs(v1-TARGET)
    error2 = abs(v2-TARGET)
    sa = max(error1,error2)
    score = int(2 * 10**6 - 10**5 * math.log10(sa +1.0))    
    if isDisplay:
        print(TARGET,v1,v2)
        print(error1,error2,score)

    return score

def cal_ave(A,B, i,j):
    A[i] = (A[i] + A[j])//2
    A[j] = A[i]

    B[i] = (B[i] + B[j])//2
    B[j] = B[i]    

def save(A, B, i,j):
    return (i,j,A[i],B[i],A[j],B[j])

def restore(A, B, save):
    i,j = save[0], save[1]
    A[i],B[i],A[j],B[j] = save[2],save[3],save[4],save[5]

def main():
    args = sys.argv
    debug = False

    if len(args) >= 2:
        debug = True

    sys.setrecursionlimit(10000000)

    #H=int(input())

    #A=list(map(int,input().split()))

    #A,B=map(int,input().split())
    #A,B=input().split()

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


    
    # 入力
    N = int(input())
    A = [0] * (N +1)
    B = [0] * (N +1)
    for i in range(1,N+1):
        A[i], B[i] = map(int, input().split())


    # 出力
    print(50)
    for i in range(0, 50):
        now_score = cal_score(A[1],B[1])
        kouho = (1,1)
        for i in range(2, N + 1):
#            print("1 " + str(i))
            save_info = save(A,B,1,i)
            cal_ave(A,B,1,i)
            score = cal_score(A[1],B[1])

            restore(A,B,save_info)
            if now_score < score:
                kouho = (1,i)
        if kouho[1] ==1:
            while True:
                k,l = random.randint(2, N),random.randint(2, N)
                if k != l:
                    break
            kouho = (k,l)

        cal_ave(A,B,kouho[0],kouho[1])
        print(f"{kouho[0]} {kouho[1]}")    

        if debug:
            cal_score(A[1],B[1], True)

if __name__ == "__main__":
    main()
0