結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
17,936 KB
testcase_01 AC 65 ms
12,704 KB
testcase_02 AC 198 ms
20,468 KB
testcase_03 AC 43 ms
11,264 KB
testcase_04 AC 130 ms
16,348 KB
testcase_05 AC 174 ms
20,504 KB
testcase_06 AC 48 ms
11,392 KB
testcase_07 AC 151 ms
17,700 KB
testcase_08 AC 156 ms
18,800 KB
testcase_09 AC 172 ms
19,112 KB
testcase_10 AC 206 ms
21,060 KB
testcase_11 AC 192 ms
21,060 KB
testcase_12 AC 170 ms
21,060 KB
testcase_13 AC 29 ms
9,984 KB
testcase_14 WA -
testcase_15 AC 30 ms
9,984 KB
testcase_16 AC 29 ms
9,984 KB
testcase_17 AC 29 ms
9,984 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 30 ms
9,984 KB
testcase_22 WA -
testcase_23 AC 29 ms
9,984 KB
testcase_24 AC 30 ms
9,984 KB
testcase_25 WA -
testcase_26 AC 29 ms
9,984 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 = float("inf")
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