結果

問題 No.5020 Averaging
ユーザー 寝癖寝癖
提出日時 2024-02-25 13:38:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 955 ms / 1,000 ms
コード長 1,987 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 87,512 KB
スコア 33,624,281
最終ジャッジ日時 2024-02-25 13:39:44
合計ジャッジ時間 50,198 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 939 ms
85,348 KB
testcase_01 AC 940 ms
85,904 KB
testcase_02 AC 941 ms
85,780 KB
testcase_03 AC 941 ms
86,508 KB
testcase_04 AC 941 ms
87,248 KB
testcase_05 AC 940 ms
87,372 KB
testcase_06 AC 941 ms
85,752 KB
testcase_07 AC 941 ms
86,820 KB
testcase_08 AC 941 ms
87,096 KB
testcase_09 AC 941 ms
86,592 KB
testcase_10 AC 940 ms
87,512 KB
testcase_11 AC 940 ms
86,372 KB
testcase_12 AC 940 ms
86,484 KB
testcase_13 AC 944 ms
86,340 KB
testcase_14 AC 941 ms
85,652 KB
testcase_15 AC 941 ms
86,944 KB
testcase_16 AC 955 ms
86,540 KB
testcase_17 AC 940 ms
86,568 KB
testcase_18 AC 953 ms
87,080 KB
testcase_19 AC 942 ms
86,680 KB
testcase_20 AC 941 ms
85,728 KB
testcase_21 AC 940 ms
86,356 KB
testcase_22 AC 941 ms
86,520 KB
testcase_23 AC 941 ms
87,104 KB
testcase_24 AC 941 ms
85,700 KB
testcase_25 AC 941 ms
86,792 KB
testcase_26 AC 941 ms
86,164 KB
testcase_27 AC 941 ms
87,084 KB
testcase_28 AC 941 ms
87,032 KB
testcase_29 AC 940 ms
86,272 KB
testcase_30 AC 940 ms
86,616 KB
testcase_31 AC 940 ms
85,596 KB
testcase_32 AC 940 ms
86,300 KB
testcase_33 AC 941 ms
85,764 KB
testcase_34 AC 940 ms
86,988 KB
testcase_35 AC 941 ms
86,780 KB
testcase_36 AC 940 ms
86,044 KB
testcase_37 AC 941 ms
86,140 KB
testcase_38 AC 941 ms
86,900 KB
testcase_39 AC 941 ms
86,044 KB
testcase_40 AC 939 ms
86,108 KB
testcase_41 AC 941 ms
85,908 KB
testcase_42 AC 940 ms
85,972 KB
testcase_43 AC 941 ms
86,312 KB
testcase_44 AC 941 ms
87,152 KB
testcase_45 AC 941 ms
86,836 KB
testcase_46 AC 941 ms
86,696 KB
testcase_47 AC 941 ms
86,532 KB
testcase_48 AC 941 ms
85,692 KB
testcase_49 AC 941 ms
85,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import log10, floor, exp
from random import randint, random
from time import time

time_start = time()

N = int(input())
init_A, init_B = [list(i) for i in zip(*[list(map(int, input().split())) for _ in range(N)])]

def calc_socre(op):
    A, B = exec_op(op)
    X = len(op)

    V1, V2 = abs(5*10**17-A[0]), abs(5*10**17-B[0])
    V = max(V1, V2)
    if V == 0:
        return 2000050 - X
    else:
        return floor(2000000.0 - 100000.0 * log10(V+1))

def exec_op(op):
    A, B = init_A[:], init_B[:]
    for u, v in op:
        a, b = A[u-1], A[v-1]
        A[u-1], A[v-1] = (a+b)//2, (a+b)//2
        c, d = B[u-1], B[v-1]
        B[u-1], B[v-1] = (c+d)//2, (c+d)//2
    return A, B

X = 50
op = []
for _ in range(X):
    u = randint(1, N-1)
    v = randint(u+1, N)
    op.append((u, v))

# 山登り法
# score = calc_socre(op)
# while time() - time_start < 0.90:
#     if randint(0, 1):
#         u = randint(1, N-1)
#         v = randint(u+1, N)
#         op[randint(0, X-1)] = (u, v)
#     else:
#         u, v = randint(0, X-1), randint(0, X-1)
#         op[u], op[v] = op[v], op[u]
#     new_score = calc_socre(op)
#     if new_score > score:
#         score = new_score
#     else:
#         op[u], op[v] = op[v], op[u]
    
# 焼きなまし
score = calc_socre(op)
start_temp = 2000
end_temp = 10
TIME_LIMIT = 0.90

while True:
    now_time = time() - time_start
    if now_time > TIME_LIMIT:
        break
    new_op = op[:]
    if randint(0, 1):
        u = randint(1, N-1)
        v = randint(u+1, N)
        new_op[randint(0, X-1)] = (u, v)
    else:
        u, v = randint(0, X-1), randint(0, X-1)
        new_op[u], new_op[v] = new_op[v], new_op[u]
    new_score = calc_socre(new_op)
    temp = start_temp + (end_temp - start_temp) * now_time / TIME_LIMIT
    prob = exp(min(0, (new_score - score) / temp))
    if new_score > score or random() < prob:
        op = new_op
        score = new_score

# print(score)

print(X)
for u, v in op:
    print(u, v)
0