結果

問題 No.1077 Noelちゃんと星々4
ユーザー tarattata1tarattata1
提出日時 2020-06-12 21:50:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,658 bytes
コンパイル時間 684 ms
コンパイル使用メモリ 80,616 KB
実行使用メモリ 18,776 KB
最終ジャッジ日時 2023-09-06 10:13:13
合計ジャッジ時間 1,661 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,068 KB
testcase_01 AC 2 ms
5,152 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

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][1005];
ll sdp[1005][1005];

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 <= n; j++) {
            dp[i][j] = LINF;
        }
    }
    for (j = 0; j <= 1000; 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 <= 1000; 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][1000]);

    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