結果

問題 No.2548 Problem Selection
ユーザー zezerozezero
提出日時 2023-11-25 13:49:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 818 bytes
コンパイル時間 3,454 ms
コンパイル使用メモリ 169,792 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-25 13:50:02
合計ジャッジ時間 4,576 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 7 ms
6,676 KB
testcase_04 AC 29 ms
6,676 KB
testcase_05 AC 47 ms
6,676 KB
testcase_06 AC 8 ms
6,676 KB
testcase_07 AC 34 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 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 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 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 1 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <cstring>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < int(n);i++)
using mint = modint998244353;

int main(){
  int n,m;
  cin >> n >> m;
  vector<ll> a(n);
  for (int i = 0; i < n;i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  ll ans = 1LL << 60;
  ll res = 0;
  for (int i = 0; i < m-1;i++){
    res += (a[i+1]-a[i])*(a[i+1]-a[i]);
  }
  ans = min(ans,res);
  for (int i = m-1; i < n-1;i++){
    res -= (a[i-m+2]-a[i-m+1])*(a[i-m+2]-a[i-m+1]);
    res += (a[i+1]-a[i])*(a[i+1]-a[i]);
    ans = min(ans,res);
  }
  cout << ans << endl;
  

  return 0;
}
0