結果
問題 | No.1077 Noelちゃんと星々4 |
ユーザー |
![]() |
提出日時 | 2020-06-12 23:37:07 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 51 ms / 2,000 ms |
コード長 | 713 bytes |
コンパイル時間 | 1,607 ms |
コンパイル使用メモリ | 163,424 KB |
実行使用メモリ | 42,368 KB |
最終ジャッジ日時 | 2024-06-24 06:05:14 |
合計ジャッジ時間 | 3,045 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
/*** @FileName a.cpp* @Author kanpurin* @Created 2020.06.12 23:37:02**/#include "bits/stdc++.h"using namespace std;typedef long long ll;int main() {int n;cin >> n;vector<int> a(n);for (int i = 0; i < n; i++) {cin >> a[i];}constexpr int INF = 1e9 + 6;vector<vector<int>> dp(n+1,vector<int>(10001,INF));dp[0][0] = 0;for (int i = 0; i < n; i++) {int m = INF;for (int j = 0; j <= 10000; j++) {m = min(m,dp[i][j]);dp[i + 1][j] = m + abs(a[i]-j);}}int ans = INF;for (int i = 0; i <= 10000; i++) {ans = min(ans,dp[n][i]);}cout << ans << endl;return 0;}