結果

問題 No.1077 Noelちゃんと星々4
ユーザー carrot46carrot46
提出日時 2020-06-12 21:32:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 1,119 bytes
コンパイル時間 1,633 ms
コンパイル使用メモリ 169,424 KB
実行使用メモリ 81,116 KB
最終ジャッジ日時 2023-09-06 09:52:20
合計ジャッジ時間 3,497 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 56 ms
56,612 KB
testcase_03 AC 72 ms
72,500 KB
testcase_04 AC 23 ms
23,876 KB
testcase_05 AC 17 ms
18,552 KB
testcase_06 AC 29 ms
30,208 KB
testcase_07 AC 33 ms
34,512 KB
testcase_08 AC 25 ms
25,720 KB
testcase_09 AC 22 ms
22,552 KB
testcase_10 AC 75 ms
72,800 KB
testcase_11 AC 47 ms
47,840 KB
testcase_12 AC 39 ms
39,928 KB
testcase_13 AC 17 ms
17,892 KB
testcase_14 AC 70 ms
70,860 KB
testcase_15 AC 38 ms
38,664 KB
testcase_16 AC 25 ms
26,244 KB
testcase_17 AC 43 ms
43,620 KB
testcase_18 AC 73 ms
73,716 KB
testcase_19 AC 16 ms
17,212 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 81 ms
81,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<62);

template<class T> bool chmin(T &a, const T &b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T &b){
    if(a < b) {a = b; return true;}
    else return false;
}

int main() {
    cin>>N;
    vec y(N);
    const int max_y = int(1e+4) + 1;
    mat dp(N, vec(max_y, INF));
    rep(i,N) {
        cin>>y[i];
    }
    rep(i,max_y) dp[0][i] = max(y[0] - i, 0LL);
    reps(i,1,N){
        rep(j,max_y){
            chmin(dp[i][j], dp[i-1][j] + abs(y[i] - j));
            if(j > 0) chmin(dp[i][j], dp[i][j-1]);
        }
    }
    cout<<dp[N - 1][max_y - 1]<<endl;
}
0