結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー Coki628Coki628
提出日時 2020-12-04 01:34:53
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 394 ms / 2,000 ms
コード長 1,296 bytes
コンパイル時間 2,273 ms
コンパイル使用メモリ 86,796 KB
実行使用メモリ 113,984 KB
最終ジャッジ日時 2023-10-12 12:53:17
合計ジャッジ時間 22,779 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,352 KB
testcase_01 AC 73 ms
71,448 KB
testcase_02 AC 73 ms
71,440 KB
testcase_03 AC 72 ms
71,492 KB
testcase_04 AC 74 ms
71,544 KB
testcase_05 AC 72 ms
71,492 KB
testcase_06 AC 74 ms
71,220 KB
testcase_07 AC 73 ms
71,604 KB
testcase_08 AC 79 ms
75,684 KB
testcase_09 AC 76 ms
75,600 KB
testcase_10 AC 73 ms
71,220 KB
testcase_11 AC 73 ms
71,548 KB
testcase_12 AC 77 ms
75,484 KB
testcase_13 AC 76 ms
71,436 KB
testcase_14 AC 79 ms
75,828 KB
testcase_15 AC 77 ms
75,480 KB
testcase_16 AC 80 ms
75,624 KB
testcase_17 AC 80 ms
75,668 KB
testcase_18 AC 383 ms
112,832 KB
testcase_19 AC 369 ms
108,868 KB
testcase_20 AC 245 ms
101,616 KB
testcase_21 AC 105 ms
76,308 KB
testcase_22 AC 251 ms
99,932 KB
testcase_23 AC 98 ms
76,480 KB
testcase_24 AC 307 ms
104,428 KB
testcase_25 AC 249 ms
100,528 KB
testcase_26 AC 141 ms
85,296 KB
testcase_27 AC 98 ms
76,304 KB
testcase_28 AC 393 ms
113,744 KB
testcase_29 AC 393 ms
113,484 KB
testcase_30 AC 392 ms
113,720 KB
testcase_31 AC 386 ms
113,296 KB
testcase_32 AC 394 ms
113,760 KB
testcase_33 AC 388 ms
113,720 KB
testcase_34 AC 386 ms
113,984 KB
testcase_35 AC 390 ms
113,764 KB
testcase_36 AC 386 ms
113,904 KB
testcase_37 AC 390 ms
113,976 KB
testcase_38 AC 386 ms
113,680 KB
testcase_39 AC 387 ms
113,600 KB
testcase_40 AC 383 ms
113,576 KB
testcase_41 AC 387 ms
113,504 KB
testcase_42 AC 394 ms
113,668 KB
testcase_43 AC 72 ms
71,436 KB
testcase_44 AC 72 ms
71,240 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()

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

A2 = sorted(A)
l, r = trisearch_min(0, N, check)
mn = INF
for i in range(max(l-10, 0), min(r+10, N)):
    res = check(i)
    if res < mn:
        mn = res
        ans = (A2[i], res)
print(*ans)
0