結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー NoneNone
提出日時 2021-02-23 10:08:40
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 1,795 bytes
コンパイル時間 1,692 ms
コンパイル使用メモリ 81,544 KB
実行使用メモリ 154,996 KB
最終ジャッジ日時 2023-10-22 04:58:24
合計ジャッジ時間 20,118 ms
ジャッジサーバーID
(参考情報)
judge15 / judge10
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,504 KB
testcase_01 AC 38 ms
53,516 KB
testcase_02 AC 38 ms
53,516 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
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 WA -
testcase_27 WA -
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 39 ms
53,452 KB
testcase_44 AC 38 ms
53,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Compress:
    def __init__(self,A):
        """ A=[(a,degeneracy),...] """
        S=[0]
        self.A=[]
        for a, cnt in A:
            S.append(S[-1]+cnt)
            self.A.append(a)
        self.S=S[1:]

    def __getitem__(self, i):
        j=bisect_left(self.S,i+1)
        return self.A[j]

    def sum(self, i):
        """ sum in [0,i) """
        j=bisect_left(self.S,i)
        res=0
        q=0
        for k in range(j):
            res+=self.A[k]*(self.S[k]-q)
            q=self.S[k]
        print(j, res)
        if j>0: res+=self.A[j]*(i-self.S[j-1])
        else: res+=self.A[j]*(i)
        return res

    def __iter__(self):
        l=0
        for i in range(self.S[-1]):
            if i==self.S[l]:
                l+=1
            yield self.A[l]

    def __str__(self):
        return " ".join(list(map(str, self)))

def deg(A):
    """
    連続して続く文字を圧縮する(※Counterではない)
    [1,1,1,2,2,2,3] -> [(1,3),(2,3),(3,1)]
    """
    res=[]
    a0, cnt=A[0], 1
    for a in A[1:]:
        if a!=a0: res.append((a0,cnt)); cnt=1
        else: cnt+=1
        a0=a
    res.append((a0,cnt))
    return res

def median(array):
    L = len(array)
    if L%2==0:
        return (array[L//2-1]+array[L//2])/2
    else:
        return array[L//2]

###############################################################
import sys
from bisect import *
input = sys.stdin.readline

N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
data=[]
for a,b in zip(A,B):
    data.append((a,b))

C=Compress(data)
L=sum(B)
if L%2==0:
    X=(C[L//2-1]+C[L//2])/2
    res=0
    for i in range(N):
        res+=B[i]*abs(A[i]-X)
else:
    X=C[L//2]
    res=0
    for i in range(N):
        res+=B[i]*abs(A[i]-X)
print(X,int(res))
0