結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
8,292 KB
testcase_01 AC 14 ms
8,212 KB
testcase_02 AC 15 ms
8,172 KB
testcase_03 AC 14 ms
8,160 KB
testcase_04 AC 15 ms
8,296 KB
testcase_05 AC 16 ms
8,248 KB
testcase_06 WA -
testcase_07 AC 15 ms
8,176 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 14 ms
8,160 KB
testcase_11 AC 14 ms
8,144 KB
testcase_12 AC 15 ms
8,164 KB
testcase_13 WA -
testcase_14 AC 15 ms
8,312 KB
testcase_15 AC 15 ms
8,236 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

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()

    if n == 1:
        return A[0], 0

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

    # mp = 0
    # for i in range(n):
    #     if cum[i] <= cum[n] - cum[i + 1] and cum[i + 1] > cum[n] - cum[i + 1]:
    #         mp = i
    #         break
    #     if i < n - 1 and cum[i + 1] == cum[n] - cum[i + 1]:
    #         mp = i
    #         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 _ in range(300):
        mid = (lo + hi) / 2.0
        s = 0
        i = 0
        while P[i][0] < mid:
            s += P[i][1]
            i += 1
        if s <= cum[n] - cum[i + 1]:
            lo = mid
        else:
            hi = mid

        # fx, fy = f(x), f(y)
        # if fx > fy:
        #     lo = x
        #     minima = fy
        # else:
        #     hi = y
        #     minima = fx

    return lo, int(f(lo) + 0.5)

    # if mp == n - 1:
    #     return P[mp][0], int(f(P[mp][0]) + 0.5)
    # if f(P[mp][0]) <= f(P[mp + 1][0]):
    #     return P[mp][0], int(f(P[mp][0]) + 0.5)
    # else:
    #     return P[mp + 1][0], int(f(P[mp + 1][0]) + 0.5)


print(*solve())
0