結果
問題 | No.5020 Averaging |
ユーザー | ra5anchor |
提出日時 | 2024-08-06 04:01:22 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 901 ms / 1,000 ms |
コード長 | 2,132 bytes |
コンパイル時間 | 471 ms |
コンパイル使用メモリ | 82,340 KB |
実行使用メモリ | 78,336 KB |
スコア | 14,082,931 |
最終ジャッジ日時 | 2024-08-06 04:02:11 |
合計ジャッジ時間 | 47,981 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 891 ms
77,840 KB |
testcase_01 | AC | 894 ms
77,784 KB |
testcase_02 | AC | 892 ms
77,924 KB |
testcase_03 | AC | 893 ms
78,064 KB |
testcase_04 | AC | 894 ms
77,632 KB |
testcase_05 | AC | 893 ms
77,832 KB |
testcase_06 | AC | 892 ms
77,512 KB |
testcase_07 | AC | 894 ms
78,284 KB |
testcase_08 | AC | 892 ms
78,044 KB |
testcase_09 | AC | 891 ms
77,984 KB |
testcase_10 | AC | 890 ms
77,760 KB |
testcase_11 | AC | 890 ms
77,636 KB |
testcase_12 | AC | 890 ms
78,168 KB |
testcase_13 | AC | 890 ms
78,168 KB |
testcase_14 | AC | 890 ms
78,136 KB |
testcase_15 | AC | 890 ms
77,792 KB |
testcase_16 | AC | 891 ms
77,812 KB |
testcase_17 | AC | 890 ms
78,120 KB |
testcase_18 | AC | 889 ms
77,764 KB |
testcase_19 | AC | 889 ms
78,048 KB |
testcase_20 | AC | 890 ms
78,172 KB |
testcase_21 | AC | 892 ms
78,136 KB |
testcase_22 | AC | 891 ms
78,284 KB |
testcase_23 | AC | 901 ms
77,728 KB |
testcase_24 | AC | 891 ms
78,188 KB |
testcase_25 | AC | 889 ms
77,796 KB |
testcase_26 | AC | 891 ms
78,136 KB |
testcase_27 | AC | 890 ms
77,760 KB |
testcase_28 | AC | 892 ms
77,984 KB |
testcase_29 | AC | 890 ms
78,144 KB |
testcase_30 | AC | 890 ms
78,092 KB |
testcase_31 | AC | 892 ms
77,668 KB |
testcase_32 | AC | 891 ms
78,012 KB |
testcase_33 | AC | 891 ms
77,852 KB |
testcase_34 | AC | 892 ms
77,684 KB |
testcase_35 | AC | 889 ms
77,932 KB |
testcase_36 | AC | 890 ms
78,116 KB |
testcase_37 | AC | 893 ms
78,008 KB |
testcase_38 | AC | 891 ms
78,336 KB |
testcase_39 | AC | 892 ms
77,904 KB |
testcase_40 | AC | 892 ms
77,964 KB |
testcase_41 | AC | 892 ms
77,988 KB |
testcase_42 | AC | 892 ms
78,020 KB |
testcase_43 | AC | 891 ms
78,104 KB |
testcase_44 | AC | 892 ms
78,116 KB |
testcase_45 | AC | 891 ms
77,884 KB |
testcase_46 | AC | 890 ms
77,748 KB |
testcase_47 | AC | 890 ms
77,740 KB |
testcase_48 | AC | 892 ms
77,920 KB |
testcase_49 | AC | 888 ms
77,868 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 + 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]+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()