結果
問題 | No.5020 Averaging |
ユーザー | ra5anchor |
提出日時 | 2024-08-06 03:53:23 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,130 bytes |
コンパイル時間 | 353 ms |
コンパイル使用メモリ | 82,656 KB |
実行使用メモリ | 78,576 KB |
スコア | 0 |
最終ジャッジ日時 | 2024-08-06 03:54:12 |
合計ジャッジ時間 | 48,456 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | WA | - |
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 | WA | - |
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 | - |
ソースコード
import random import math from time import perf_counter import sys 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) # 定数とグローバル変数 TARGET = 500000000000000000 N = 0 A = [] B = [] Order = [] BestOrder = [] def get_score(): V1, V2 = A[0], B[0] for i in range(N - 1): V1 = (V1 + A[Order[i]]) // 2 V2 = (V2 + B[Order[i]]) // 2 return max(abs(TARGET - V1), abs(TARGET - V2)) def main(): global N, A, B, Order, BestOrder tk = TimeKeeper() LIMIT = 0.85 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()) # 初期化 Order = list(range(1, N)) current_score = get_score() best_score = current_score # 焼きなまし loop = 0 T0, T1 = 0.2, 0.2 T = T0 while True: loop += 1 if loop % 1000 == 0: T = T0 + (T1 - T0) * tk.time_now() / LIMIT if tk.is_time_over(LIMIT): break idx1 = random.randint(0, N - 2) idx2 = random.randint(0, N - 2) Order[idx1], Order[idx2] = Order[idx2], Order[idx1] cand_score = get_score() # 変更候補 diff = math.log10(current_score) - math.log10(cand_score) # diff > 0:改善 if random.random() < math.exp(diff / T): # 採用 if best_score > cand_score: best_score = cand_score BestOrder = Order[:] current_score = cand_score else: # 不採用の場合は元に戻す Order[idx1], Order[idx2] = Order[idx2], Order[idx1] ANS = [(1, BestOrder[i]) for i in range(N - 1)] print(len(ANS)) for a in ANS: print(a[0], a[1]) sc = int(2*10**6 - 10**5 * math.log10(best_score + 1)) print(sc, best_score, loop, file=sys.stderr) if __name__ == "__main__": main()