結果

問題 No.5020 Averaging
ユーザー ra5anchorra5anchor
提出日時 2024-04-14 16:00:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 994 ms / 1,000 ms
コード長 5,521 bytes
コンパイル時間 567 ms
コンパイル使用メモリ 82,828 KB
実行使用メモリ 83,436 KB
スコア 16,789,581
最終ジャッジ日時 2024-04-14 16:01:36
合計ジャッジ時間 52,418 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 964 ms
82,836 KB
testcase_01 AC 994 ms
83,436 KB
testcase_02 AC 958 ms
83,184 KB
testcase_03 AC 959 ms
83,196 KB
testcase_04 AC 992 ms
82,948 KB
testcase_05 AC 957 ms
83,312 KB
testcase_06 AC 961 ms
83,068 KB
testcase_07 AC 961 ms
83,160 KB
testcase_08 AC 958 ms
83,292 KB
testcase_09 AC 958 ms
83,044 KB
testcase_10 AC 958 ms
83,156 KB
testcase_11 AC 954 ms
83,096 KB
testcase_12 AC 953 ms
83,028 KB
testcase_13 AC 956 ms
83,044 KB
testcase_14 AC 956 ms
83,060 KB
testcase_15 AC 955 ms
82,992 KB
testcase_16 AC 957 ms
83,068 KB
testcase_17 AC 959 ms
83,224 KB
testcase_18 AC 957 ms
83,344 KB
testcase_19 AC 958 ms
83,052 KB
testcase_20 AC 955 ms
83,136 KB
testcase_21 AC 956 ms
82,996 KB
testcase_22 AC 957 ms
83,152 KB
testcase_23 AC 958 ms
83,272 KB
testcase_24 AC 968 ms
83,132 KB
testcase_25 AC 959 ms
83,064 KB
testcase_26 AC 957 ms
83,176 KB
testcase_27 AC 964 ms
83,044 KB
testcase_28 AC 955 ms
83,316 KB
testcase_29 AC 960 ms
83,408 KB
testcase_30 AC 958 ms
83,288 KB
testcase_31 AC 959 ms
83,092 KB
testcase_32 AC 957 ms
83,096 KB
testcase_33 AC 960 ms
83,040 KB
testcase_34 AC 956 ms
83,348 KB
testcase_35 AC 957 ms
83,104 KB
testcase_36 AC 960 ms
83,224 KB
testcase_37 AC 994 ms
83,060 KB
testcase_38 AC 956 ms
83,072 KB
testcase_39 AC 964 ms
83,192 KB
testcase_40 AC 956 ms
83,128 KB
testcase_41 AC 957 ms
83,272 KB
testcase_42 AC 962 ms
83,120 KB
testcase_43 AC 956 ms
83,160 KB
testcase_44 AC 956 ms
83,164 KB
testcase_45 AC 957 ms
83,048 KB
testcase_46 AC 957 ms
83,268 KB
testcase_47 AC 958 ms
82,992 KB
testcase_48 AC 957 ms
83,000 KB
testcase_49 AC 956 ms
83,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import copy
import random
from time import perf_counter
import argparse
import sys
import math

class TimeKeeper:
    def __init__(self):
        self.start_time = perf_counter()
    def is_time_over(self, LIMIT):
        return (perf_counter() - self.start_time) >= LIMIT
    def time_now(self):
        return (perf_counter() - self.start_time)

def calscore(ans, C0):
    C = C0[:]
    X = len(ans)
    sc = 0
    for i in range(X):
        u, v = ans[i]
        a0, b0 = C[u]
        a1, b1 = C[v]
        C[u] = (a0 + a1)//2, (b0 + b1)//2
        C[v] = (a0 + a1)//2, (b0 + b1)//2
    V1 = abs(C[0][0] - 5*10**17)
    V2 = abs(C[0][1] - 5*10**17)
    sc = int(2*10**6 - 10**5 * math.log10(max(V1, V2) + 1))
    return sc


###########################################
def main(DEBUG):
    tk = TimeKeeper()
    if DEBUG == True:
        LIMIT = 0.85
    else:
        LIMIT = 0.85

    def output(ans):
        print(len(ans))
        for i in range(len(ans)):
            u, v = ans[i]
            u += 1
            v += 1
            print(u, v)
        return

    def solve1(LIMIT):
        C = C0[:]
        ans = []
        a0 = C[0][0]
        b0 = C[0][1]
        V1 = abs(a0 - 5*10**17)
        V2 = abs(b0 - 5*10**17)
        nowV = max(V1, V2)
        while len(ans) < 50:
            if tk.is_time_over(LIMIT):
                break
            for i in range(1, N):
                ai, bi = C[i][0], C[i][1]
                nxV1 = abs((a0 + ai) // 2 - 5*10**17)
                nxV2 = abs((b0 + bi) // 2 - 5*10**17)
                nxtV = max(nxV1, nxV2)
                if nxtV < nowV:
                    nowV = nxtV
                    a0 = (a0 + ai) // 2
                    b0 = (b0 + bi) // 2
                    C[i] = (a0, b0)
                    ans.append((0, i))
                    sc = int(2*10**6 - 10**5 * math.log10(nowV + 1))
                    print(sc, nowV, a0, b0, file=sys.stderr)
        return ans

    def solve2(LIMIT):
        C = C0[:]
        ans = []
        a0 = C[0][0]
        b0 = C[0][1]
        V1 = abs(a0 - 5*10**17)
        V2 = abs(b0 - 5*10**17)
        nowV = max(V1, V2)
        finish = False
        while len(ans) < 50 and finish == False:
            finish = True
            for i in range(1, N):
                ai, bi = C[i][0], C[i][1]
                nxV1 = abs((a0 + ai) // 2 - 5*10**17)
                nxV2 = abs((b0 + bi) // 2 - 5*10**17)
                nxtV = max(nxV1, nxV2)
                if nxtV < nowV:
                    nowV = nxtV
                    a0 = (a0 + ai) // 2
                    b0 = (b0 + bi) // 2
                    C[i] = (a0, b0)
                    ans.append((0, i))
                    sc = int(2*10**6 - 10**5 * math.log10(nowV + 1))
                    print(sc, nowV, a0, b0, file=sys.stderr)
                    finish = False

        ###
        while True:
            if tk.is_time_over(LIMIT):
                print("timeover", file=sys.stderr)
                break
            inow = random.randint(1, N-1)
            a0 = C[inow][0]
            b0 = C[inow][1]
            V1 = abs(a0 - 5*10**17)
            V2 = abs(b0 - 5*10**17)
            nowV = max(V1, V2)
            finish = False
            while len(ans) < 50 and finish == False:
                finish = True
                for i in range(1, N):
                    if i == inow:
                        continue
                    ai, bi = C[i][0], C[i][1]
                    nxV1 = abs((a0 + ai) // 2 - 5*10**17)
                    nxV2 = abs((b0 + bi) // 2 - 5*10**17)
                    nxtV = max(nxV1, nxV2)
                    if nxtV < nowV:
                        nowV = nxtV
                        a0 = (a0 + ai) // 2
                        b0 = (b0 + bi) // 2
                        C[i] = (a0, b0)
                        ans.append((inow, i))
                        # sc = int(2*10**6 - 10**5 * math.log10(nowV + 1))
                        # print(sc, nowV, a0, b0, file=sys.stderr)
                        finish = False

            a0 = C[0][0]
            b0 = C[0][1]
            V1 = abs(a0 - 5*10**17)
            V2 = abs(b0 - 5*10**17)
            nowV = max(V1, V2)
            finish = False
            while len(ans) < 50 and finish == False:
                finish = True
                for i in range(1, N):
                    ai, bi = C[i][0], C[i][1]
                    nxV1 = abs((a0 + ai) // 2 - 5*10**17)
                    nxV2 = abs((b0 + bi) // 2 - 5*10**17)
                    nxtV = max(nxV1, nxV2)
                    if nxtV < nowV:
                        nowV = nxtV
                        a0 = (a0 + ai) // 2
                        b0 = (b0 + bi) // 2
                        C[i] = (a0, b0)
                        ans.append((0, i))
                        sc = int(2*10**6 - 10**5 * math.log10(nowV + 1))
                        print(sc, nowV, a0, b0, file=sys.stderr)
                        finish = False
        return ans

    def solve3(LIMIT):
        C = C0[:]
        ans = []

    N = int(input())
    C0 = []
    for i in range(N):
        a, b = map(int, input().split())
        C0.append((a, b))

    ans = solve2(LIMIT)
    sc = calscore(ans[:50], C0)

    print("SC", sc, file=sys.stderr)    
    output(ans[:50])
    return
    

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Debug mode')
    parser.add_argument('--debug', action='store_true', help='Enable debug mode')
    args = parser.parse_args()
    main(args.debug)
0