結果
| 問題 |
No.3268 As Seen in Toasters
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-23 19:19:38 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 47 ms / 2,000 ms |
| コード長 | 802 bytes |
| コンパイル時間 | 3,864 ms |
| コンパイル使用メモリ | 283,768 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-09-23 19:19:47 |
| 合計ジャッジ時間 | 8,610 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 41 |
ソースコード
// #pragma GCC optimize ("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target ("avx,avx2,fma")
#include <bits/stdc++.h>
using std::cin, std::cout, std::cerr;
using ll = long long;
int main() {
std::ios::sync_with_stdio(false);
int n; cin >> n;
std::vector<int> a(n);
for(int i = 0; i < n; i ++)
cin >> a[i];
std::sort(a.begin(), a.end());
auto f = [](auto a) {
ll r = 0;
for(int i = 0; i + 1 < a.size(); i ++) {
ll x = a[i], y = a[i + 1];
if(x < 0 && y < 0)
r += -x - y;
else
r += std::abs(x - y);
}
return r;
};
ll ans = f(a);
std::rotate(a.begin() + 1, a.begin() + 2, a.end());
ans = std::min(ans, f(a));
cout << ans << '\n';
}