結果
問題 |
No.838 Noelちゃんと星々3
|
ユーザー |
|
提出日時 | 2025-10-01 12:45:39 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 31 ms / 2,000 ms |
コード長 | 680 bytes |
コンパイル時間 | 2,864 ms |
コンパイル使用メモリ | 283,296 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-10-01 12:45:45 |
合計ジャッジ時間 | 4,839 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
// #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()); std::vector<ll> f(n + 1, 1e18L); f[0] = 0; for(int i = 1; i <= n; i ++) { if(i >= 2) f[i] = std::min(f[i], f[i - 2] + a[i - 1] - a[i - 2]); if(i >= 3) f[i] = std::min(f[i], f[i - 3] + a[i - 1] - a[i - 3]); } cout << f[n] << '\n'; }