結果

問題 No.1391 ±1 Abs Sum
ユーザー titiatitia
提出日時 2023-05-22 07:58:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 781 bytes
コンパイル時間 331 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 115,464 KB
最終ジャッジ日時 2023-08-23 19:48:41
合計ジャッジ時間 11,567 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,200 KB
testcase_01 AC 70 ms
71,048 KB
testcase_02 AC 70 ms
71,136 KB
testcase_03 AC 71 ms
71,260 KB
testcase_04 WA -
testcase_05 AC 72 ms
71,136 KB
testcase_06 WA -
testcase_07 AC 72 ms
71,224 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 261 ms
99,844 KB
testcase_15 WA -
testcase_16 AC 302 ms
100,340 KB
testcase_17 WA -
testcase_18 AC 353 ms
110,408 KB
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 AC 387 ms
114,868 KB
testcase_32 AC 200 ms
96,780 KB
testcase_33 AC 209 ms
101,648 KB
testcase_34 AC 144 ms
111,688 KB
testcase_35 AC 72 ms
71,148 KB
testcase_36 AC 143 ms
115,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N,K=map(int,input().split())
A=list(map(int,input().split()))

S=[0]
for a in A:
    S.append(S[-1]+a)

plus=K
minus=N-K

def calc(i,j):
    a=A[i]
    ANS=S[i+1]-a*(i+1)
    ANS+=a*(N-i-1)-(S[-1]-S[i+1])

    if j+K-1<=i:
        ANS+=2*(a*K-S[j+K]-S[j])
    elif j>=i:
        ANS+=2*(S[j+K]-S[j]-a*K)
    else:
        ANS+=2*(a*(i-j)-S[i]-S[j])
        ANS+=2*(S[j+K]-S[i]-a*(j+K-i))

    return ANS

LANS=1<<100
for i in range(N):
    MIN=0
    MAX=N-K

    while MAX>MIN+5:
        mid1=MIN+(MAX-MIN)//3
        mid2=MIN+(MAX-MIN)//3*2

        if calc(i,mid1)<calc(i,mid2):
            MAX=mid2
        else:
            MIN=mid1

    for j in range(MIN,MAX+1):
        LANS=min(LANS,calc(i,j))

print(LANS)
        
        
        
0