結果

問題 No.1077 Noelちゃんと星々4
ユーザー snow39snow39
提出日時 2020-06-12 22:05:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,117 bytes
コンパイル時間 841 ms
コンパイル使用メモリ 94,296 KB
実行使用メモリ 42,584 KB
最終ジャッジ日時 2023-09-06 10:29:50
合計ジャッジ時間 2,188 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 30 ms
32,096 KB
testcase_03 AC 37 ms
38,436 KB
testcase_04 AC 13 ms
15,724 KB
testcase_05 AC 10 ms
11,544 KB
testcase_06 AC 16 ms
17,808 KB
testcase_07 AC 18 ms
19,732 KB
testcase_08 AC 14 ms
15,700 KB
testcase_09 AC 12 ms
13,652 KB
testcase_10 AC 37 ms
38,168 KB
testcase_11 AC 25 ms
25,936 KB
testcase_12 AC 22 ms
23,892 KB
testcase_13 AC 11 ms
11,612 KB
testcase_14 AC 37 ms
38,224 KB
testcase_15 AC 20 ms
21,844 KB
testcase_16 AC 14 ms
15,640 KB
testcase_17 AC 23 ms
23,840 KB
testcase_18 AC 38 ms
40,228 KB
testcase_19 AC 10 ms
11,628 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 42 ms
42,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

const int L=1e4;
const int INF=1e9;

int dp[1010][10010];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin>>N;
  vector<int> A(N);
  rep(i,N) cin>>A[i];

  rep(i,N+1) rep(j,L+1) dp[i][j]=INF;
  rep(j,L+1) dp[0][j]=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<=L;j++){
      if(dp[i][j]==INF) continue;

      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]));
    }

    int mi=INF;
    for(int j=0;j<=A[i];j++){
      chmin(mi,dp[i][j]);
      chmin(dp[i+1][j],mi+A[i]-j);
    }
  }

  int ans=INF;
  rep(j,L+1) chmin(ans,dp[N][j]);

  cout<<ans<<endl;

  return 0;
}
0