結果

問題 No.837 Noelちゃんと星々2
ユーザー titiatitia
提出日時 2019-06-15 03:47:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,247 bytes
コンパイル時間 112 ms
コンパイル使用メモリ 10,864 KB
実行使用メモリ 27,868 KB
最終ジャッジ日時 2023-08-10 08:45:17
合計ジャッジ時間 7,806 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N=int(input())
Y=list(map(int,input().split()))
MIN=min(Y)
Y=[y-MIN for y in Y]


if max(Y)==min(Y):
    print(1)
    sys.exit()

Y.sort()

MIN=1
MAX=N-1

while True:
    x=(MIN+MAX)//2
    y=x+1

    B=Y[:x]
    C=Y[x:]

    SUM=sum(B)
    ANS=SUM
    LEN=len(B)
    NOW=0

    for i in range(LEN):
        SUM+=(B[i]-NOW)*i+(NOW-B[i])*(LEN-i)
        ANS=min(ANS,SUM)
        NOW=B[i]

    SUM=sum(C)
    ANS2=SUM
    LEN=len(C)
    NOW=0

    for i in range(LEN):
        SUM+=(C[i]-NOW)*i+(NOW-C[i])*(LEN-i)
        ANS2=min(ANS2,SUM)
        NOW=C[i]

    D=Y[:y]
    E=Y[y:]

    SUM=sum(D)
    ANS3=SUM
    LEN=len(D)
    NOW=0

    for i in range(LEN):
        SUM+=(D[i]-NOW)*i+(NOW-D[i])*(LEN-i)
        ANS3=min(ANS3,SUM)
        NOW=D[i]

    SUM=sum(E)
    ANS4=SUM
    LEN=len(E)
    NOW=0

    for i in range(LEN):
        SUM+=(E[i]-NOW)*i+(NOW-E[i])*(LEN-i)
        ANS4=min(ANS4,SUM)
        NOW=E[i]

    #print(x,y)
    #print(ANS,ANS2,ANS3,ANS4)

    if ANS+ANS2==ANS3+ANS4:
        print(ANS+ANS2)
        sys.exit()

    elif MAX==MIN:
        print(min(ANS+ANS2,ANS3+ANS4))
        sys.exit()
              

    elif ANS+ANS2<ANS3+ANS4:
        MAX=x
    else:
        MIN=y
        
0