結果

問題 No.1077 Noelちゃんと星々4
ユーザー totori_nyaatotori_nyaa
提出日時 2020-06-12 21:31:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,021 bytes
コンパイル時間 1,643 ms
コンパイル使用メモリ 166,300 KB
実行使用メモリ 42,708 KB
最終ジャッジ日時 2023-09-06 09:52:16
合計ジャッジ時間 2,852 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 33 ms
32,072 KB
testcase_03 AC 41 ms
38,144 KB
testcase_04 AC 14 ms
15,696 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 20 ms
19,840 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 11 ms
11,536 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 1 ms
4,380 KB
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);

int dp[1001][10001];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);


    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans = 1e9;
    int ma = 10001;
    for(int i=0;i<=n;i++){
        for(int j=0;j<ma;j++){
            dp[i][j] = 1e9;
        }
    }
    dp[0][0] = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<ma;j++){
            if(j<=a[i])chmin(dp[i+1][a[i]],dp[i][j]);
            chmin(dp[i+1][j],dp[i][j]+abs(j-a[i]));
            if(j) chmin(dp[i+1][j],dp[i+1][j-1]);
        }
    }
    for(int i=0;i<ma;i++)chmin(ans,dp[n][i]);
    cout << ans << endl;
}
0