結果
問題 | No.1077 Noelちゃんと星々4 |
ユーザー |
![]() |
提出日時 | 2020-06-13 01:51:02 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 56 ms / 2,000 ms |
コード長 | 658 bytes |
コンパイル時間 | 1,984 ms |
コンパイル使用メモリ | 172,432 KB |
実行使用メモリ | 42,368 KB |
最終ジャッジ日時 | 2024-06-24 06:17:01 |
合計ジャッジ時間 | 2,889 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
#include<bits/stdc++.h>using namespace std;using ll = long long;const int INF = 1e9;const int high = 1e4+1;int main(){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>(high, INF)); //dp[i][j] := a[i]の段差j以下に行くときの最小コストfor(int i = 0; i < high; i++)dp[0][i] = 0;for(int i = 0; i < n; i++) {for(int j = 0; j < high; j++) {dp[i + 1][j] = min(dp[i + 1][j], abs(a[i] - j) + dp[i][j]);if(j != 0)dp[i + 1][j] = min(dp[i + 1][j - 1], dp[i + 1][j]);}}cout << dp[n][high-1] << endl;}