結果
| 問題 |
No.3268 As Seen in Toasters
|
| コンテスト | |
| ユーザー |
apricity
|
| 提出日時 | 2025-07-26 23:42:35 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 116 ms / 2,000 ms |
| コード長 | 842 bytes |
| コンパイル時間 | 1,037 ms |
| コンパイル使用メモリ | 106,340 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-09-08 04:12:58 |
| 合計ジャッジ時間 | 5,026 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 41 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long f(long long x, long long y) {
return x < 0 and y < 0 ? -x-y : abs(x-y);
}
int main() {
int n; cin >> n;
vector<long long> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
sort(a.begin(), a.end());
vector<long long> b{a.front()};
for (int i = 2; i < n; i++) b.emplace_back(a[i]);
b.emplace_back(a[1]);
if (a.back() < 0){
long long ans = 0;
for (int i = 0; i < n-1; i++) ans += f(b[i], b[i+1]);
cout << ans << "\n";
return 0;
}
long long ans = 0;
for (int i = 0; i < n-1; i++) ans += f(a[i], a[i+1]);
if (a[1] < 0){
long long ans2 = 0;
for (int i = 0; i < n-1; i++) ans2 += f(b[i], b[i+1]);
ans = min(ans, ans2);
}
cout << ans << "\n";
}
apricity