結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー keijakkeijak
提出日時 2020-10-09 22:14:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,290 bytes
コンパイル時間 83 ms
コンパイル使用メモリ 10,852 KB
実行使用メモリ 51,600 KB
最終ジャッジ日時 2023-09-27 17:45:55
合計ジャッジ時間 22,335 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,192 KB
testcase_01 AC 15 ms
8,164 KB
testcase_02 AC 15 ms
8,172 KB
testcase_03 AC 14 ms
8,212 KB
testcase_04 AC 15 ms
8,228 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 14 ms
8,264 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 15 ms
8,196 KB
testcase_11 AC 15 ms
8,224 KB
testcase_12 AC 14 ms
7,880 KB
testcase_13 WA -
testcase_14 AC 14 ms
8,324 KB
testcase_15 AC 15 ms
8,324 KB
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 AC 79 ms
16,168 KB
testcase_27 AC 33 ms
10,568 KB
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 AC 15 ms
7,892 KB
testcase_44 AC 15 ms
8,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    n = ini()
    A = inl()
    B = inl()

    P = []
    for i in range(n):
        P.append((A[i], B[i]))
    P.sort()

    cum = [None] * (n + 1)
    cum[0] = 0
    for i in range(n):
        cum[i + 1] = cum[i] + P[i][1]

    mp = P[0][0]
    for i in range(n):
        if cum[i] <= cum[n] - cum[i + 1] and cum[i + 1] > cum[n] - cum[i + 1]:
            mp = P[i][0]
            break
        if i < n - 1 and cum[i + 1] == cum[n] - cum[i + 1]:
            mp = (P[i][0] + P[i + 1][0]) * 0.5
            break

    def f(x):
        res = 0
        for i in range(n):
            res += B[i] * abs(x - A[i])
        return res

    # lo, hi, minima = min(A) - 1, max(A) + 1, None
    # for i in range(300):
    #     x = lo + (hi - lo) / 3.0
    #     y = lo + (hi - lo) * 2.0 / 3.0
    #     fx, fy = f(x), f(y)
    #     if fx > fy:
    #         lo = x
    #         minima = fy
    #     else:
    #         hi = y
    #         minima = fx
    return mp, int(f(mp) + 0.5)


print(*solve())
0