結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー Coki628Coki628
提出日時 2020-12-04 00:45:36
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,313 bytes
コンパイル時間 326 ms
コンパイル使用メモリ 87,548 KB
実行使用メモリ 114,520 KB
最終ジャッジ日時 2023-10-12 11:34:45
合計ジャッジ時間 21,397 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,856 KB
testcase_01 AC 73 ms
71,816 KB
testcase_02 AC 72 ms
71,612 KB
testcase_03 AC 71 ms
71,824 KB
testcase_04 AC 72 ms
71,624 KB
testcase_05 AC 72 ms
71,652 KB
testcase_06 AC 73 ms
71,620 KB
testcase_07 AC 72 ms
71,620 KB
testcase_08 AC 75 ms
75,740 KB
testcase_09 AC 72 ms
71,856 KB
testcase_10 AC 71 ms
71,792 KB
testcase_11 AC 72 ms
71,652 KB
testcase_12 AC 71 ms
71,708 KB
testcase_13 AC 71 ms
71,640 KB
testcase_14 AC 75 ms
75,944 KB
testcase_15 AC 74 ms
75,772 KB
testcase_16 AC 73 ms
75,864 KB
testcase_17 AC 77 ms
75,948 KB
testcase_18 AC 327 ms
113,412 KB
testcase_19 AC 317 ms
109,336 KB
testcase_20 AC 213 ms
101,832 KB
testcase_21 AC 98 ms
76,476 KB
testcase_22 AC 220 ms
100,548 KB
testcase_23 AC 91 ms
76,692 KB
testcase_24 AC 266 ms
105,012 KB
testcase_25 AC 217 ms
100,832 KB
testcase_26 AC 126 ms
85,300 KB
testcase_27 AC 92 ms
76,736 KB
testcase_28 WA -
testcase_29 AC 338 ms
113,676 KB
testcase_30 AC 340 ms
113,920 KB
testcase_31 AC 333 ms
113,976 KB
testcase_32 AC 337 ms
114,012 KB
testcase_33 AC 328 ms
113,940 KB
testcase_34 AC 331 ms
114,388 KB
testcase_35 AC 343 ms
113,892 KB
testcase_36 AC 333 ms
114,312 KB
testcase_37 AC 333 ms
114,128 KB
testcase_38 AC 333 ms
114,008 KB
testcase_39 AC 331 ms
114,076 KB
testcase_40 AC 332 ms
113,792 KB
testcase_41 AC 332 ms
113,776 KB
testcase_42 AC 338 ms
114,148 KB
testcase_43 RE -
testcase_44 AC 72 ms
71,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for k in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10**9)
INF = 10**19
MOD = 10**9 + 7
EPS = 10**-10

def trisearch_min(lo, hi, func):
    """ 三分探索 """

    m1 = lo
    m2 = hi
    while lo+2 < hi:
        m1 = (lo*2+hi) // 3
        m2 = (lo+hi*2) // 3
        res1 = func(m1)
        res2 = func(m2)
        if res1 <= res2:
            hi = m2
        else:
            lo = m1
    return m1, m2

N = INT()
A = LIST()
B = LIST()

if N == 1:
    print(A[0], 0)
    exit()

def check(m):
    res = 0
    for i in range(N):
        res += B[i] * abs(A2[m]-A[i])
    return res

A2 = sorted(A)
res = trisearch_min(0, N, check)
ans1 = check(res[0])
ans2 = check(res[1])
if ans1 <= ans2:
    print(A2[res[0]], ans1)
else:
    print(A2[res[1]], ans2)
0