結果
問題 | No.5020 Averaging |
ユーザー | Mao-beta |
提出日時 | 2024-02-25 15:23:13 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 706 ms / 1,000 ms |
コード長 | 2,696 bytes |
コンパイル時間 | 274 ms |
コンパイル使用メモリ | 81,700 KB |
実行使用メモリ | 83,504 KB |
スコア | 21,333,090 |
最終ジャッジ日時 | 2024-02-25 15:23:47 |
合計ジャッジ時間 | 33,014 ms |
ジャッジサーバーID (参考情報) |
judge10 / judge11 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 627 ms
82,096 KB |
testcase_01 | AC | 632 ms
82,356 KB |
testcase_02 | AC | 628 ms
82,100 KB |
testcase_03 | AC | 659 ms
82,228 KB |
testcase_04 | AC | 358 ms
80,052 KB |
testcase_05 | AC | 538 ms
81,588 KB |
testcase_06 | AC | 660 ms
83,120 KB |
testcase_07 | AC | 588 ms
81,972 KB |
testcase_08 | AC | 607 ms
81,972 KB |
testcase_09 | AC | 645 ms
82,608 KB |
testcase_10 | AC | 649 ms
82,224 KB |
testcase_11 | AC | 567 ms
81,712 KB |
testcase_12 | AC | 424 ms
80,820 KB |
testcase_13 | AC | 456 ms
80,944 KB |
testcase_14 | AC | 536 ms
80,948 KB |
testcase_15 | AC | 666 ms
82,736 KB |
testcase_16 | AC | 366 ms
80,176 KB |
testcase_17 | AC | 579 ms
82,356 KB |
testcase_18 | AC | 706 ms
83,504 KB |
testcase_19 | AC | 635 ms
81,972 KB |
testcase_20 | AC | 659 ms
82,868 KB |
testcase_21 | AC | 684 ms
82,352 KB |
testcase_22 | AC | 540 ms
82,484 KB |
testcase_23 | AC | 597 ms
82,356 KB |
testcase_24 | AC | 581 ms
81,712 KB |
testcase_25 | AC | 652 ms
82,484 KB |
testcase_26 | AC | 645 ms
82,864 KB |
testcase_27 | AC | 669 ms
82,352 KB |
testcase_28 | AC | 655 ms
82,472 KB |
testcase_29 | AC | 555 ms
82,356 KB |
testcase_30 | AC | 686 ms
83,380 KB |
testcase_31 | AC | 646 ms
82,992 KB |
testcase_32 | AC | 437 ms
81,328 KB |
testcase_33 | AC | 621 ms
82,344 KB |
testcase_34 | AC | 590 ms
82,352 KB |
testcase_35 | AC | 437 ms
80,948 KB |
testcase_36 | AC | 582 ms
82,100 KB |
testcase_37 | AC | 607 ms
82,216 KB |
testcase_38 | AC | 579 ms
82,084 KB |
testcase_39 | AC | 483 ms
81,328 KB |
testcase_40 | AC | 633 ms
83,120 KB |
testcase_41 | AC | 614 ms
82,484 KB |
testcase_42 | AC | 490 ms
80,820 KB |
testcase_43 | AC | 589 ms
82,100 KB |
testcase_44 | AC | 617 ms
82,736 KB |
testcase_45 | AC | 609 ms
82,224 KB |
testcase_46 | AC | 506 ms
81,972 KB |
testcase_47 | AC | 603 ms
82,228 KB |
testcase_48 | AC | 496 ms
81,076 KB |
testcase_49 | AC | 604 ms
82,468 KB |
ソースコード
import sys import math import bisect from heapq import heapify, heappop, heappush from collections import deque, defaultdict, Counter from functools import lru_cache from itertools import accumulate, combinations, permutations, product sys.setrecursionlimit(1000000) MOD = 10 ** 9 + 7 MOD99 = 998244353 input = lambda: sys.stdin.readline().strip() NI = lambda: int(input()) NMI = lambda: map(int, input().split()) NLI = lambda: list(NMI()) SI = lambda: input() SMI = lambda: input().split() SLI = lambda: list(SMI()) EI = lambda m: [NLI() for _ in range(m)] def score(a, b, x): v1 = abs(5 * 10**17 - a) v2 = abs(5 * 10**17 - b) if max(v1, v2) > 0: return int(2000000 - 100000 * math.log10(max(v1, v2)+1)) else: return 2000050 - x def answer(ans): print(len(ans)) for i, j in ans: print(i+1, j+1) def greedy(): N = NI() AB = EI(N) ans = [] # 0と何かだけで貪欲 for qi in range(50): a0, b0 = AB[0] s = score(a0, b0, qi) best_s = s best_v = 1 for v in range(1, N): av, bv = AB[v] na, nb = (a0+av) // 2, (b0+bv) // 2 ns = score(na, nb, qi+1) if ns > best_s: best_s = ns best_v = v if best_s > s: av, bv = AB[best_v] na, nb = (a0 + av) // 2, (b0 + bv) // 2 AB[0] = [na, nb] AB[best_v] = [na, nb] ans.append([0, best_v]) else: break answer(ans) def means(AB, i, j): ai, bi = AB[i] aj, bj = AB[j] na, nb = (ai + aj) // 2, (bi + bj) // 2 return na, nb def query(AB, i, j): na, nb = means(AB, i, j) AB[i] = [na, nb] AB[j] = [na, nb] def total_score(AB): res = 0 for a, b in AB: res += score(a, b, 0) return res def calc_gap(AB, i, j): # ABについてi, jを操作したときのスコアの差分 na, nb = means(AB, i, j) after = score(na, nb, 0) * 2 before = score(AB[i][0], AB[i][1], 0) + score(AB[j][0], AB[j][1], 0) return after - before def main(): N = NI() AB = EI(N) total = total_score(AB) ans = [] # totalが改善するように山登り for qi in range(50): max_gap = 0 best_ij = [0, 1] for i in range(N): for j in range(i+1, N): gap = calc_gap(AB, i, j) if gap > max_gap: max_gap = gap best_ij = [i, j] if max_gap > 0: query(AB, *best_ij) ans.append(best_ij) else: break answer(ans) if __name__ == "__main__": main()