結果

問題 No.1077 Noelちゃんと星々4
ユーザー hs0319boyhs0319boy
提出日時 2020-06-12 23:12:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,067 bytes
コンパイル時間 1,347 ms
コンパイル使用メモリ 168,800 KB
実行使用メモリ 42,032 KB
最終ジャッジ日時 2023-09-06 11:16:27
合計ジャッジ時間 2,849 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 37 ms
30,024 KB
testcase_03 AC 47 ms
38,000 KB
testcase_04 AC 15 ms
13,292 KB
testcase_05 AC 13 ms
11,068 KB
testcase_06 AC 20 ms
16,544 KB
testcase_07 AC 23 ms
18,656 KB
testcase_08 AC 17 ms
14,368 KB
testcase_09 AC 15 ms
12,752 KB
testcase_10 AC 49 ms
37,920 KB
testcase_11 AC 32 ms
25,512 KB
testcase_12 AC 26 ms
21,616 KB
testcase_13 AC 11 ms
10,464 KB
testcase_14 AC 46 ms
37,104 KB
testcase_15 AC 27 ms
21,108 KB
testcase_16 AC 18 ms
14,772 KB
testcase_17 AC 29 ms
23,340 KB
testcase_18 AC 49 ms
38,652 KB
testcase_19 AC 11 ms
10,168 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 54 ms
42,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int n;cin>>n;
    vin y(n);rep(i,n)cin>>y[i];
    vvin dp(n,vin(10001));
    rep(i,10001)dp[0][i]=abs(i-y[0]);
    rep(i,n-1)rep(j,10001){
        dp[i+1][j]=dp[i][j]+abs(j-y[i+1]);
        if(j>0)dp[i+1][j]=min(dp[i+1][j],dp[i+1][j-1]-abs(j-1-y[i+1])+abs(j-y[i+1]));
    }
    int ans=inf;
    rep(i,10001)ans=min(ans,dp[n-1][i]);
    cout<<ans<<endl;
}
0