結果

問題 No.2548 Problem Selection
ユーザー Nikkuniku029Nikkuniku029
提出日時 2023-11-25 13:37:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 198 ms / 2,000 ms
コード長 410 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 21,064 KB
最終ジャッジ日時 2023-11-25 13:37:12
合計ジャッジ時間 3,572 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
17,940 KB
testcase_01 AC 61 ms
12,708 KB
testcase_02 AC 188 ms
20,472 KB
testcase_03 AC 40 ms
11,264 KB
testcase_04 AC 119 ms
16,352 KB
testcase_05 AC 154 ms
20,508 KB
testcase_06 AC 46 ms
11,392 KB
testcase_07 AC 140 ms
17,704 KB
testcase_08 AC 141 ms
18,804 KB
testcase_09 AC 166 ms
19,116 KB
testcase_10 AC 198 ms
21,064 KB
testcase_11 AC 162 ms
21,064 KB
testcase_12 AC 150 ms
21,064 KB
testcase_13 AC 27 ms
9,984 KB
testcase_14 AC 28 ms
9,984 KB
testcase_15 AC 27 ms
9,984 KB
testcase_16 AC 26 ms
9,984 KB
testcase_17 AC 28 ms
9,984 KB
testcase_18 AC 27 ms
9,984 KB
testcase_19 AC 27 ms
9,984 KB
testcase_20 AC 27 ms
9,984 KB
testcase_21 AC 28 ms
9,984 KB
testcase_22 AC 27 ms
9,984 KB
testcase_23 AC 28 ms
9,984 KB
testcase_24 AC 28 ms
9,984 KB
testcase_25 AC 27 ms
9,984 KB
testcase_26 AC 28 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()
if M == 1:
    ans = 0
print(ans)
0