結果
| 問題 |
No.2548 Problem Selection
|
| コンテスト | |
| ユーザー |
millfi_
|
| 提出日時 | 2023-11-25 13:27:01 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,134 bytes |
| コンパイル時間 | 1,931 ms |
| コンパイル使用メモリ | 173,876 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-26 10:26:27 |
| 合計ジャッジ時間 | 3,190 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 24 WA * 1 |
ソースコード
#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;
}
millfi_