結果
問題 | No.1077 Noelちゃんと星々4 |
ユーザー |
|
提出日時 | 2020-07-03 20:04:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 28 ms / 2,000 ms |
コード長 | 581 bytes |
コンパイル時間 | 2,816 ms |
コンパイル使用メモリ | 194,764 KB |
最終ジャッジ日時 | 2025-01-11 14:10:45 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
#define _USE_MATH_DEFINES#include <bits/stdc++.h>using namespace std;const int M = 12000;signed main() {ios::sync_with_stdio(false); cin.tie(0);int n;cin >> n;vector<int> a(n);for (int i = 0; i < n; i++) {cin >> a[i];}vector<int> dp(M, 1 << 30);dp[0] = 0;for (int i = 0; i < n; i++) {vector<int> nxt(M, 1 << 30);int mi = 1 << 30;for (int j = 0; j < M; j++) {mi = min(mi, dp[j]);nxt[j] = min(nxt[j], mi + abs(a[i] - j));}dp.swap(nxt);}cout << *min_element(dp.begin(), dp.end()) << endl;return 0;}