結果
問題 |
No.3268 As Seen in Toasters
|
ユーザー |
![]() |
提出日時 | 2025-09-12 22:13:59 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 114 ms / 2,000 ms |
コード長 | 466 bytes |
コンパイル時間 | 3,184 ms |
コンパイル使用メモリ | 281,744 KB |
実行使用メモリ | 7,720 KB |
最終ジャッジ日時 | 2025-09-12 23:41:26 |
合計ジャッジ時間 | 7,307 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
#include<bits/stdc++.h> using namespace std; int main(){ using ll=long long; int n; cin>>n; vector<ll> a(n); for (int i=0;i<n;i++) cin>>a[i]; auto f=[&](ll x,ll y){ if (x<0&&y<0) return -(x+y); else return abs(x-y); }; ll ans=1e18; auto g=[&](){ ll s=0; for (int i=0;i<n-1;i++) s+=f(a[i],a[i+1]); if (ans>s) ans=s; }; sort(a.begin(),a.end()); g(); for (int i=1;i<n-1;i++) swap(a[i],a[i+1]); g(); cout<<ans<<endl; }