結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー uni_pythonuni_python
提出日時 2020-10-10 11:43:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,773 ms / 2,000 ms
コード長 870 bytes
コンパイル時間 471 ms
コンパイル使用メモリ 86,920 KB
実行使用メモリ 109,240 KB
最終ジャッジ日時 2023-09-27 21:21:07
合計ジャッジ時間 48,837 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,304 KB
testcase_01 AC 72 ms
75,516 KB
testcase_02 AC 74 ms
75,732 KB
testcase_03 AC 71 ms
75,552 KB
testcase_04 AC 72 ms
75,748 KB
testcase_05 AC 73 ms
75,804 KB
testcase_06 AC 72 ms
75,672 KB
testcase_07 AC 73 ms
75,612 KB
testcase_08 AC 74 ms
75,804 KB
testcase_09 AC 71 ms
75,748 KB
testcase_10 AC 73 ms
75,768 KB
testcase_11 AC 70 ms
75,696 KB
testcase_12 AC 73 ms
75,768 KB
testcase_13 AC 72 ms
75,708 KB
testcase_14 AC 74 ms
75,760 KB
testcase_15 AC 74 ms
75,788 KB
testcase_16 AC 72 ms
75,820 KB
testcase_17 AC 72 ms
75,828 KB
testcase_18 AC 1,534 ms
108,572 KB
testcase_19 AC 1,634 ms
104,860 KB
testcase_20 AC 871 ms
99,600 KB
testcase_21 AC 183 ms
76,176 KB
testcase_22 AC 1,035 ms
98,160 KB
testcase_23 AC 154 ms
76,412 KB
testcase_24 AC 1,250 ms
100,600 KB
testcase_25 AC 1,009 ms
98,928 KB
testcase_26 AC 393 ms
83,848 KB
testcase_27 AC 156 ms
76,364 KB
testcase_28 AC 1,619 ms
109,152 KB
testcase_29 AC 1,773 ms
108,856 KB
testcase_30 AC 1,621 ms
108,772 KB
testcase_31 AC 1,636 ms
109,116 KB
testcase_32 AC 1,738 ms
109,084 KB
testcase_33 AC 1,739 ms
108,908 KB
testcase_34 AC 1,628 ms
109,104 KB
testcase_35 AC 1,616 ms
109,004 KB
testcase_36 AC 1,612 ms
108,716 KB
testcase_37 AC 1,765 ms
109,240 KB
testcase_38 AC 1,741 ms
109,124 KB
testcase_39 AC 1,611 ms
108,804 KB
testcase_40 AC 1,577 ms
109,076 KB
testcase_41 AC 1,632 ms
108,796 KB
testcase_42 AC 1,625 ms
109,000 KB
testcase_43 AC 68 ms
75,028 KB
testcase_44 AC 76 ms
75,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    
    N=I()
    A=LI()
    B=LI()
    
    def calc(x):
        res=0
        for i in range(N):
            res+=B[i]*abs(x-A[i])
        return res
        
    
    M=10**6+5
    left=-M
    right=M
    
    for i in range(300):
        c1=(2*left+right)//3
        c2=(left+2*right)//3
        
        if calc(c1)<calc(c2):
            right=c2
        else:
            left=c1
            
            
    aaa=int((right+left)//2)
    ansx=aaa
    ans=calc(aaa)
    
    # for i in range(20):
    #     ii=i-10
    #     x=aaa+0.5*ii
    #     temp=calc(x)
    #     if temp<ans:
    #         ans=temp
    #         ansx=x
            
    print(ansx,int(ans))
    
        
    


main()
0