結果

問題 No.1077 Noelちゃんと星々4
ユーザー tarattata1tarattata1
提出日時 2020-06-12 21:55:52
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,667 bytes
コンパイル時間 769 ms
コンパイル使用メモリ 82,628 KB
実行使用メモリ 159,936 KB
最終ジャッジ日時 2024-06-24 04:56:12
合計ジャッジ時間 2,204 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

ll dp[1005][10005];
ll sdp[1005][10005];

void solve()
{
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    int i, j;
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    for (i = 0; i <= n; i++) {
        for (j = 0; j <= 10000; j++) {
            dp[i][j] = LINF;
        }
    }
    for (j = 0; j <= 10000; j++) {
        dp[0][j] = abs(j - a[0]);
        if (j > 0) sdp[0][j] = MIN(sdp[0][j - 1], dp[0][j]);
        else       sdp[0][j] = dp[0][j];
    }    
    for (i = 1; i < n; i++) {
        for (j = 0; j <= 10000; j++) {
            dp[i][j] = sdp[i - 1][j] + abs(j - a[i]);

            if (j > 0) sdp[i][j] = MIN(sdp[i][j - 1], dp[i][j]);
            else       sdp[i][j] = dp[i][j];
        }
    }
    printf("%lld\n", sdp[n - 1][10000]);

    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}
0