結果

問題 No.2548 Problem Selection
ユーザー anonymouslyanonymously
提出日時 2023-12-01 21:51:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 718 bytes
コンパイル時間 1,856 ms
コンパイル使用メモリ 172,136 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-01 21:51:33
合計ジャッジ時間 3,942 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
6,676 KB
testcase_01 AC 13 ms
6,676 KB
testcase_02 AC 47 ms
6,676 KB
testcase_03 AC 7 ms
6,676 KB
testcase_04 AC 29 ms
6,676 KB
testcase_05 AC 48 ms
6,676 KB
testcase_06 AC 8 ms
6,676 KB
testcase_07 AC 35 ms
6,676 KB
testcase_08 AC 40 ms
6,676 KB
testcase_09 AC 42 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 1 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 1 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 1 ms
6,676 KB
testcase_23 AC 20 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> A(n);
	for(int i=0;i<n;i++){
		cin >> A[i];
	}
	sort(A.begin(),A.end());
	
	//ソートした状態で問題の選択をスキップすると、評価値が跳ね上がる(難易度の差の2乗なので)
	//なので、ソートした状態でM問連続で選択するものとする。
	
	//最初のM問選択する
	long s=0;
	for(int i=1;i<m;i++){
		s+=(long)(A[i]-A[i-1])*(A[i]-A[i-1]);
	}
	long S=s;
	
	//尺取り法で評価値を計算する
	for(int i=m;i<n;i++){
		s+=((long)(A[i]-A[i-1])*(A[i]-A[i-1])-(long)(A[i-m+1]-A[i-m])*(A[i-m+1]-A[i-m]));
		if(s<S)S=s;
	}
	
	cout << S << endl;
	return 0;
}
0