結果

問題 No.1077 Noelちゃんと星々4
ユーザー ____________
提出日時 2020-06-12 22:03:38
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 1,337 bytes
コンパイル時間 2,245 ms
コンパイル使用メモリ 203,188 KB
実行使用メモリ 81,176 KB
最終ジャッジ日時 2023-09-06 10:29:46
合計ジャッジ時間 3,591 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 61 ms
56,700 KB
testcase_03 AC 75 ms
72,488 KB
testcase_04 AC 23 ms
23,908 KB
testcase_05 AC 18 ms
18,688 KB
testcase_06 AC 30 ms
30,256 KB
testcase_07 AC 35 ms
34,452 KB
testcase_08 AC 26 ms
25,684 KB
testcase_09 AC 21 ms
22,564 KB
testcase_10 AC 75 ms
72,668 KB
testcase_11 AC 48 ms
47,888 KB
testcase_12 AC 40 ms
39,964 KB
testcase_13 AC 17 ms
17,760 KB
testcase_14 AC 76 ms
70,848 KB
testcase_15 AC 39 ms
38,752 KB
testcase_16 AC 25 ms
26,544 KB
testcase_17 AC 45 ms
43,752 KB
testcase_18 AC 76 ms
73,792 KB
testcase_19 AC 16 ms
17,284 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 85 ms
81,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using Tup = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fl cout<<flush;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld pi=3.141592653589793238;
int N;
vector<int> Y(1003,0);

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    cin >> N;
    for(int i=0;i<N;++i)cin>>Y[i];
    //dp[i][j]はY[i]までを見て、最後jの最小コスト
    vector<vector<ll>> dp(N, vector<ll>(10001, INF));
    for(ll j=0;j<10001;++j){
        dp[0][j]=llabs(Y[0]-j);
    }
    for(ll i=1;i<N;++i){
        for(ll j=0;j<10001;++j){
            if(j>0)
            chmin(dp[i][j],dp[i][j-1]-llabs(Y[i]-(j-1))+llabs(Y[i]-j));
            chmin(dp[i][j],dp[i-1][j]+llabs(Y[i]-j));
        }
    }
    ll ans=INF;
    for(ll i=0;i<10001;++i)chmin(ans,dp[N-1][i]);
    prt(ans)fl

    return 0;
}
0