結果

問題 No.1077 Noelちゃんと星々4
ユーザー furafura
提出日時 2020-06-12 22:10:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 487 bytes
コンパイル時間 2,091 ms
コンパイル使用メモリ 200,420 KB
実行使用メモリ 42,744 KB
最終ジャッジ日時 2023-09-06 10:31:19
合計ジャッジ時間 3,332 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 22 ms
32,208 KB
testcase_03 AC 26 ms
38,356 KB
testcase_04 AC 9 ms
15,848 KB
testcase_05 AC 8 ms
11,676 KB
testcase_06 AC 11 ms
17,820 KB
testcase_07 AC 12 ms
19,924 KB
testcase_08 AC 10 ms
16,056 KB
testcase_09 AC 10 ms
13,764 KB
testcase_10 AC 27 ms
38,280 KB
testcase_11 AC 19 ms
26,060 KB
testcase_12 AC 16 ms
23,996 KB
testcase_13 AC 8 ms
11,756 KB
testcase_14 AC 26 ms
38,476 KB
testcase_15 AC 15 ms
21,996 KB
testcase_16 AC 11 ms
15,768 KB
testcase_17 AC 17 ms
24,088 KB
testcase_18 AC 27 ms
40,384 KB
testcase_19 AC 8 ms
11,708 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 30 ms
42,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int INF=1<<29;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	static int dp[1000][10001];
	rep(i,n) rep(j,10001) dp[i][j]=INF;
	rep(j,10001) dp[0][j]=abs(a[0]-j);
	rep(i,n-1){
		int mn=INF;
		rep(j,10001){
			mn=min(mn,dp[i][j]);
			dp[i+1][j]=min(dp[i+1][j],mn+abs(a[i+1]-j));
		}
	}
	printf("%d\n",*min_element(dp[n-1],dp[n-1]+10001));

	return 0;
}
0