結果
| 問題 | 
                            No.1077 Noelちゃんと星々4
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Im_Gimlet
                         | 
                    
| 提出日時 | 2020-09-05 01:16:53 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 42 ms / 2,000 ms | 
| コード長 | 1,051 bytes | 
| コンパイル時間 | 1,513 ms | 
| コンパイル使用メモリ | 168,888 KB | 
| 実行使用メモリ | 43,136 KB | 
| 最終ジャッジ日時 | 2024-11-26 21:26:31 | 
| 合計ジャッジ時間 | 2,806 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 20 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }
int dp[1010][10100];
const int INF = 1e9;
int main() {
    int n; cin >> n;
    vector<int> yvec(n, 0);
    for(int i = 0; i < n; ++i) cin >> yvec[i];
    for(int i = 0; i <= n; ++i) {
        for(int j = 0; j <= 10000; ++j) {
            dp[i][j] = INF;
        }
    }
    for(int i = 0; i <= 10000; ++i) dp[0][i] = 0;
    for(int i = 0; i < n; ++i) {
        int maxn = INF;
        for(int j = 0; j <= 10000; ++j) {
            chmin(maxn, dp[i][j]);
            chmin(dp[i+1][j], maxn + abs(yvec[i]-j));
        }
    }
    int ans = INF;
    for(int i = 0; i <= 10000; ++i) chmin(ans, dp[n][i]);
    cout << ans << endl;
}
            
            
            
        
            
Im_Gimlet