結果

問題 No.1077 Noelちゃんと星々4
ユーザー leaf_1415leaf_1415
提出日時 2020-06-12 21:28:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,133 bytes
コンパイル時間 626 ms
コンパイル使用メモリ 73,868 KB
実行使用メモリ 81,820 KB
最終ジャッジ日時 2023-09-06 09:48:06
合計ジャッジ時間 2,097 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 31 ms
58,740 KB
testcase_03 AC 39 ms
73,020 KB
testcase_04 AC 14 ms
26,076 KB
testcase_05 AC 10 ms
19,760 KB
testcase_06 AC 16 ms
32,100 KB
testcase_07 AC 18 ms
36,160 KB
testcase_08 AC 15 ms
27,956 KB
testcase_09 AC 13 ms
23,908 KB
testcase_10 AC 38 ms
73,004 KB
testcase_11 AC 25 ms
48,412 KB
testcase_12 AC 21 ms
42,264 KB
testcase_13 AC 10 ms
19,808 KB
testcase_14 AC 37 ms
73,008 KB
testcase_15 AC 20 ms
40,476 KB
testcase_16 AC 15 ms
27,932 KB
testcase_17 AC 23 ms
44,320 KB
testcase_18 AC 38 ms
75,072 KB
testcase_19 AC 10 ms
17,716 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 42 ms
81,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint a[1005];
llint dp[1005][10005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= 10000; j++){
			dp[i][j] = inf;
		}
	}
	dp[0][0] = 0;
	for(int i = 1; i <= n; i++){
		llint mn = inf;
		for(int j = 0; j <= 10000; j++){
			mn = min(mn, dp[i-1][j]);
			chmin(dp[i][j], mn+abs(j-a[i]));
		}
	}
	
	llint ans = inf;
	for(int j = 0; j <= 10000; j++) ans = min(ans, dp[n][j]);
	cout << ans << endl;
	
	return 0;
}
0