結果
問題 | No.1077 Noelちゃんと星々4 |
ユーザー |
|
提出日時 | 2020-09-02 15:07:32 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 46 ms / 2,000 ms |
コード長 | 851 bytes |
コンパイル時間 | 2,042 ms |
コンパイル使用メモリ | 192,324 KB |
最終ジャッジ日時 | 2025-01-14 03:33:03 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define REP(i,n) for(int i=0; i<(int)(n); i++)#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)#define ALL(x) (x).begin(), (x).end()const double PI = acos(-1);int n;int y[1000];int dp[1000][10000+1];int main() {ios_base::sync_with_stdio(0);cin.tie(0);cin >> n;REP (i, n) cin >> y[i];for (int h = 0; h <= 10000; h++)dp[0][h] = abs(h - y[0]);for (int i = 1; i < n; i++) {for (int h = 0; h <= 10000; h++) {dp[i][h] = dp[i-1][h] + abs(h - y[i]);if (h > 0) {if (y[i] > h-1)dp[i][h] = min(dp[i][h], dp[i][h-1] - 1);elsedp[i][h] = min(dp[i][h], dp[i][h-1] + 1);}}}int ret = 1<<30;for (int h = 0; h <= 10000; h++)ret = min(ret, dp[n-1][h]);cout << ret << endl;return 0;}