結果

問題 No.1077 Noelちゃんと星々4
ユーザー tarattata1tarattata1
提出日時 2020-06-12 21:55:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,667 bytes
コンパイル時間 615 ms
コンパイル使用メモリ 80,716 KB
実行使用メモリ 159,852 KB
最終ジャッジ日時 2023-09-06 10:20:26
合計ジャッジ時間 2,100 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,496 KB
testcase_01 AC 3 ms
5,812 KB
testcase_02 AC 45 ms
113,612 KB
testcase_03 AC 57 ms
144,340 KB
testcase_04 AC 19 ms
48,100 KB
testcase_05 AC 14 ms
35,724 KB
testcase_06 AC 23 ms
60,380 KB
testcase_07 AC 26 ms
68,504 KB
testcase_08 AC 20 ms
52,128 KB
testcase_09 AC 18 ms
43,996 KB
testcase_10 AC 57 ms
144,288 KB
testcase_11 AC 38 ms
95,196 KB
testcase_12 AC 32 ms
80,868 KB
testcase_13 AC 14 ms
35,796 KB
testcase_14 AC 57 ms
142,312 KB
testcase_15 AC 32 ms
76,772 KB
testcase_16 AC 21 ms
52,120 KB
testcase_17 AC 35 ms
87,000 KB
testcase_18 AC 60 ms
146,404 KB
testcase_19 AC 14 ms
33,708 KB
testcase_20 AC 2 ms
5,156 KB
testcase_21 AC 65 ms
159,852 KB
権限があれば一括ダウンロードができます

ソースコード

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