結果

問題 No.1077 Noelちゃんと星々4
ユーザー umezoumezo
提出日時 2020-06-12 23:18:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 835 bytes
コンパイル時間 2,333 ms
コンパイル使用メモリ 220,624 KB
実行使用メモリ 42,468 KB
最終ジャッジ日時 2023-09-06 11:21:38
合計ジャッジ時間 3,679 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 16 ms
30,696 KB
testcase_03 AC 20 ms
39,576 KB
testcase_04 AC 8 ms
15,096 KB
testcase_05 AC 6 ms
12,520 KB
testcase_06 AC 10 ms
17,360 KB
testcase_07 AC 10 ms
19,096 KB
testcase_08 AC 9 ms
15,048 KB
testcase_09 AC 7 ms
13,184 KB
testcase_10 AC 20 ms
38,784 KB
testcase_11 AC 14 ms
26,960 KB
testcase_12 AC 11 ms
22,164 KB
testcase_13 AC 6 ms
11,452 KB
testcase_14 AC 20 ms
37,864 KB
testcase_15 AC 11 ms
21,492 KB
testcase_16 AC 8 ms
15,588 KB
testcase_17 AC 12 ms
24,164 KB
testcase_18 AC 20 ms
39,400 KB
testcase_19 AC 6 ms
12,256 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 23 ms
42,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    cin>>n;
    
    int A[1010];
    rep(i,n) cin>>A[i];
    
    int dp[1010][10010];
    
    rep(j,10010) dp[0][j]=0;
    
    for(int i=0;i<=n;i++){
        int min=1000000000;
        for(int j=0;j<=10000;j++){
            if(min>dp[i][j]) min=dp[i][j];
            dp[i+1][j]=min+abs(A[i]-j);
        }
    }
    
    int ans=1000000000;
    rep(i,10001){
        if(dp[n][i]<ans) ans=dp[n][i];
    }
    
    cout<<ans<<endl;
    
  return 0;
}
0