結果

問題 No.1077 Noelちゃんと星々4
ユーザー watasihakodamawatasihakodama
提出日時 2020-06-12 21:36:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 1,674 bytes
コンパイル時間 1,569 ms
コンパイル使用メモリ 171,436 KB
実行使用メモリ 163,364 KB
最終ジャッジ日時 2023-09-06 09:55:56
合計ジャッジ時間 4,034 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,376 KB
testcase_01 AC 4 ms
4,944 KB
testcase_02 AC 106 ms
113,248 KB
testcase_03 AC 134 ms
145,616 KB
testcase_04 AC 42 ms
45,920 KB
testcase_05 AC 32 ms
35,316 KB
testcase_06 AC 55 ms
58,716 KB
testcase_07 AC 66 ms
67,440 KB
testcase_08 AC 45 ms
49,752 KB
testcase_09 AC 40 ms
43,188 KB
testcase_10 AC 136 ms
145,616 KB
testcase_11 AC 90 ms
95,204 KB
testcase_12 AC 74 ms
78,996 KB
testcase_13 AC 30 ms
33,668 KB
testcase_14 AC 133 ms
142,424 KB
testcase_15 AC 71 ms
76,576 KB
testcase_16 AC 46 ms
51,148 KB
testcase_17 AC 82 ms
86,236 KB
testcase_18 AC 138 ms
148,188 KB
testcase_19 AC 30 ms
32,268 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 152 ms
163,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
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; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
const ll mod = 1000000007;
// const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"
#define TO_STRING(VariableName) # VariableName

template <typename T>ostream &operator<<(ostream &out,const vector<T> &v) {rep(i,(int)v.size()-1)cout<<v[i]<<" ";cout<<v[(int)v.size()-1];return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const map<T1, T2> &p) {out << "(" << p.first << ", " << p.second << ")";return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const pair<T1, T2> &p){out << "(" << p.first << ", " << p.second << ")";return out;}
template<class T>void debag(const T &obj){cout<<obj<<endl;}

bool solve(){
	ll n;cin>>n;
	ll m=20000;
	vector<ll>y(n);
	rep(i,n)cin>>y[i];
	vector<vector<ll>>dp(n+1,vector<ll>(m+1,INF));
	dp[0][0]=0;
	vector<ll>ma(m+1,INF);
	rep(i,n){
		ll num=INF;
		rep(j,m+1){
			chmin(num,dp[i][j]);
			dp[i+1][j]=num+abs(j-y[i]);
		}
	}
	ll ans=INF;
	rep(j,m+1)chmin(ans,dp[n][j]);
	cout<<ans<<endl;
  	return false;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(15);
 solve();
}
0