結果

問題 No.2548 Problem Selection
ユーザー Nikkuniku029Nikkuniku029
提出日時 2023-11-25 13:05:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 382 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 11,776 KB
実行使用メモリ 21,060 KB
最終ジャッジ日時 2023-11-25 13:05:55
合計ジャッジ時間 3,587 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
17,936 KB
testcase_01 AC 66 ms
12,704 KB
testcase_02 AC 196 ms
20,468 KB
testcase_03 AC 45 ms
11,136 KB
testcase_04 AC 128 ms
16,348 KB
testcase_05 AC 175 ms
20,504 KB
testcase_06 AC 49 ms
11,264 KB
testcase_07 AC 151 ms
17,700 KB
testcase_08 AC 158 ms
18,800 KB
testcase_09 AC 177 ms
19,112 KB
testcase_10 AC 207 ms
21,060 KB
testcase_11 AC 187 ms
21,060 KB
testcase_12 AC 196 ms
21,060 KB
testcase_13 AC 30 ms
9,856 KB
testcase_14 WA -
testcase_15 AC 29 ms
9,856 KB
testcase_16 AC 30 ms
9,856 KB
testcase_17 AC 29 ms
9,856 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 29 ms
9,856 KB
testcase_22 WA -
testcase_23 AC 29 ms
9,856 KB
testcase_24 AC 29 ms
9,856 KB
testcase_25 WA -
testcase_26 AC 30 ms
9,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import pairwise
from collections import deque

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
C = []
for x, y in pairwise(A):
    C.append((y - x) ** 2)
q = deque()
ans = 1 << 60
tmp = 0
for i in range(len(C)):
    q.append(C[i])
    tmp += C[i]
    if len(q) == M - 1:
        ans = min(ans, tmp)
        tmp -= q.popleft()
print(ans)
0