結果

問題 No.2548 Problem Selection
ユーザー millfi_millfi_
提出日時 2023-11-25 13:27:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,134 bytes
コンパイル時間 1,873 ms
コンパイル使用メモリ 173,548 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-25 13:27:05
合計ジャッジ時間 3,659 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
6,676 KB
testcase_01 AC 13 ms
6,676 KB
testcase_02 AC 47 ms
6,676 KB
testcase_03 AC 6 ms
6,676 KB
testcase_04 AC 29 ms
6,676 KB
testcase_05 AC 46 ms
6,676 KB
testcase_06 AC 7 ms
6,676 KB
testcase_07 AC 35 ms
6,676 KB
testcase_08 AC 39 ms
6,676 KB
testcase_09 AC 41 ms
6,676 KB
testcase_10 AC 49 ms
6,676 KB
testcase_11 AC 49 ms
6,676 KB
testcase_12 AC 49 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 1 ms
6,676 KB
testcase_15 AC 1 ms
6,676 KB
testcase_16 AC 1 ms
6,676 KB
testcase_17 AC 1 ms
6,676 KB
testcase_18 AC 1 ms
6,676 KB
testcase_19 AC 1 ms
6,676 KB
testcase_20 AC 1 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 WA -
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(int i = 0; i < (int)(n); ++i)
#define rep2(i, n) for(int i = 0; i < (int)(n); ++i)
#define rep3(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep4(i, a, b, c) for(int i = (a); i < (int)(b); i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using u16 = uint16_t;
const ll INF = 1 << 30;
int main(){
    size_t N{}; size_t M{};
	cin >> N >> M;
	vector<ll> problems(N);
	rep(i,N)cin >> problems.at(i);
	sort(problems.begin(), problems.end());
	ull cnt = 0;
	rep(i,M-1){
		cnt += abs(problems.at(i) - problems.at(i+1)) * abs(problems.at(i) - problems.at(i+1));
	}
	ull S = cnt;
	rep(i,1,N-M){
		size_t r = M+i-1;
		size_t l = i;
		//cout << "l,r = " << l << " " << r << endl;
		cnt -= abs(problems.at(l) - problems.at(l-1)) * abs(problems.at(l) - problems.at(l-1));
		cnt += abs(problems.at(r) - problems.at(r-1)) * abs(problems.at(r) - problems.at(r-1));
		S = min(S, cnt);
	}
	cout << S << endl;
}
0