結果
問題 | No.1077 Noelちゃんと星々4 |
ユーザー |
![]() |
提出日時 | 2020-06-12 21:32:48 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 47 ms / 2,000 ms |
コード長 | 573 bytes |
コンパイル時間 | 1,573 ms |
コンパイル使用メモリ | 172,644 KB |
実行使用メモリ | 42,368 KB |
最終ジャッジ日時 | 2024-06-24 04:31:38 |
合計ジャッジ時間 | 2,816 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h> using namespace std; int INF = 100000000; int main(){ int N; cin >> N; vector<int> Y(N); for (int i = 0; i < N; i++){ cin >> Y[i]; } vector<vector<int>> dp(N + 1, vector<int>(10001, INF)); dp[0][0] = 0; for (int i = 0; i < N; i++){ for (int j = 1; j <= 10000; j++){ dp[i][j] = min(dp[i][j], dp[i][j - 1]); } for (int j = 0; j <= 10000; j++){ dp[i + 1][j] = dp[i][j] + abs(j - Y[i]); } } int ans = INF; for (int i = 0; i <= 10000; i++){ ans = min(ans, dp[N][i]); } cout << ans << endl; }