結果
問題 |
No.1077 Noelちゃんと星々4
|
ユーザー |
|
提出日時 | 2023-06-19 00:23:32 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 49 ms / 2,000 ms |
コード長 | 717 bytes |
コンパイル時間 | 3,116 ms |
コンパイル使用メモリ | 249,580 KB |
実行使用メモリ | 42,496 KB |
最終ジャッジ日時 | 2024-06-26 10:46:10 |
合計ジャッジ時間 | 3,874 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.hpp" #else #define debug(...) 1 #endif const int mxY = 10005; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<vector<int>> dp(n + 1, vector<int>(mxY, -(1 << 30))); fill(dp[0].begin(), dp[0].end(), 0); for (int i = 0; i < n; i++) { for (int j = 0; j < mxY; j++) { dp[i + 1][j] = dp[i][j] + abs(j - a[i]); } for (int j = 1; j < mxY; j++) { dp[i + 1][j] = min(dp[i + 1][j], dp[i + 1][j - 1]); } } cout << dp[n][mxY - 1] << '\n'; }