結果
| 問題 |
No.837 Noelちゃんと星々2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-03-02 20:11:33 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 81 ms / 2,000 ms |
| コード長 | 1,102 bytes |
| コンパイル時間 | 936 ms |
| コンパイル使用メモリ | 100,844 KB |
| 実行使用メモリ | 11,392 KB |
| 最終ジャッジ日時 | 2024-06-11 14:30:20 |
| 合計ジャッジ時間 | 2,665 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 29 |
ソースコード
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long y[100010], y2[100010];
long long l[100010] = {}, r[100010] = {};
set<long long> st;
int main(){
long long n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> y[i];
st.insert(y[i]);
}
if (st.size() == 1) {
cout << 1 << endl;
return 0;
}
sort(y, y + n);
for (int i = 0; i < n; i++) {
y2[i] = -y[n - i - 1];
}
long long now = y[0];
for (int i = 1; i < n; i++) {
if (i % 2 == 0) {
l[i] += y[i / 2] - now;
now = y[i / 2];
}
l[i] += l[i - 1];
l[i] += y[i - 1] - y[i / 2];
}
now = y2[0];
for (int i = 1; i < n; i++) {
if (i % 2 == 0) {
r[i] += y2[i / 2] - now;
now = y2[i / 2];
}
r[i] += r[i - 1];
r[i] += y2[i - 1] - y2[i / 2];
}
long long ans = 100000000000000007;
for (int i = 1; i < n; i++) {
ans = min(ans, l[i] + r[n - i]);
}
cout << ans << endl;
}