結果
| 問題 |
No.1077 Noelちゃんと星々4
|
| コンテスト | |
| ユーザー |
misora192
|
| 提出日時 | 2020-06-13 07:27:25 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 2,000 ms |
| コード長 | 714 bytes |
| コンパイル時間 | 1,843 ms |
| コンパイル使用メモリ | 168,596 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-24 17:03:51 |
| 合計ジャッジ時間 | 2,645 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<ll> y(n);
rep(i, n) cin >> y[i];
int max_y = 10101;
ll dp[2][max_y];
rep(i, 2) rep(j, max_y) dp[i][j] = 0;
rep(i, n){
ll mn = 1e15;
rep(j, max_y){
chmin(mn, dp[i%2][j]);
dp[(i+1)%2][j] = mn + abs(j - y[i]);
}
}
ll ans = 1e15;
rep(i, max_y) chmin(ans, dp[n%2][i]);
cout << ans << endl;
}
misora192