結果
問題 | No.5020 Averaging |
ユーザー | ra5anchor |
提出日時 | 2024-08-06 04:20:21 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 893 ms / 1,000 ms |
コード長 | 2,111 bytes |
コンパイル時間 | 520 ms |
コンパイル使用メモリ | 82,368 KB |
実行使用メモリ | 78,176 KB |
スコア | 82,486,339 |
最終ジャッジ日時 | 2024-08-06 04:21:10 |
合計ジャッジ時間 | 48,158 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 892 ms
77,836 KB |
testcase_01 | AC | 891 ms
77,772 KB |
testcase_02 | AC | 892 ms
77,676 KB |
testcase_03 | AC | 891 ms
77,804 KB |
testcase_04 | AC | 892 ms
77,876 KB |
testcase_05 | AC | 893 ms
77,816 KB |
testcase_06 | AC | 890 ms
78,072 KB |
testcase_07 | AC | 891 ms
77,808 KB |
testcase_08 | AC | 891 ms
77,960 KB |
testcase_09 | AC | 891 ms
77,780 KB |
testcase_10 | AC | 891 ms
77,608 KB |
testcase_11 | AC | 892 ms
78,048 KB |
testcase_12 | AC | 891 ms
77,684 KB |
testcase_13 | AC | 891 ms
78,004 KB |
testcase_14 | AC | 891 ms
77,748 KB |
testcase_15 | AC | 891 ms
78,084 KB |
testcase_16 | AC | 892 ms
77,760 KB |
testcase_17 | AC | 893 ms
77,616 KB |
testcase_18 | AC | 891 ms
78,044 KB |
testcase_19 | AC | 892 ms
78,176 KB |
testcase_20 | AC | 892 ms
77,980 KB |
testcase_21 | AC | 892 ms
77,776 KB |
testcase_22 | AC | 893 ms
77,936 KB |
testcase_23 | AC | 891 ms
78,080 KB |
testcase_24 | AC | 893 ms
77,884 KB |
testcase_25 | AC | 891 ms
77,684 KB |
testcase_26 | AC | 891 ms
78,028 KB |
testcase_27 | AC | 892 ms
77,796 KB |
testcase_28 | AC | 891 ms
77,608 KB |
testcase_29 | AC | 892 ms
77,588 KB |
testcase_30 | AC | 891 ms
77,688 KB |
testcase_31 | AC | 892 ms
77,892 KB |
testcase_32 | AC | 893 ms
77,920 KB |
testcase_33 | AC | 891 ms
77,644 KB |
testcase_34 | AC | 892 ms
77,968 KB |
testcase_35 | AC | 891 ms
77,544 KB |
testcase_36 | AC | 893 ms
77,776 KB |
testcase_37 | AC | 893 ms
77,932 KB |
testcase_38 | AC | 892 ms
77,744 KB |
testcase_39 | AC | 892 ms
77,760 KB |
testcase_40 | AC | 891 ms
77,660 KB |
testcase_41 | AC | 891 ms
77,896 KB |
testcase_42 | AC | 892 ms
77,828 KB |
testcase_43 | AC | 893 ms
78,032 KB |
testcase_44 | AC | 892 ms
77,836 KB |
testcase_45 | AC | 892 ms
77,904 KB |
testcase_46 | AC | 892 ms
77,784 KB |
testcase_47 | AC | 892 ms
77,652 KB |
testcase_48 | AC | 892 ms
77,660 KB |
testcase_49 | AC | 892 ms
77,684 KB |
ソースコード
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 B = [0] * N for i in range(N): 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.randrange(N - 1) idx2 = random.randrange(N - 1) 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]+1) 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()