結果

問題 No.1077 Noelちゃんと星々4
ユーザー 夜
提出日時 2020-11-12 00:52:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 801 bytes
コンパイル時間 763 ms
コンパイル使用メモリ 91,368 KB
実行使用メモリ 42,800 KB
最終ジャッジ日時 2023-09-30 00:59:29
合計ジャッジ時間 2,720 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 39 ms
30,484 KB
testcase_03 AC 49 ms
38,364 KB
testcase_04 AC 16 ms
13,852 KB
testcase_05 AC 13 ms
11,252 KB
testcase_06 AC 21 ms
17,032 KB
testcase_07 AC 24 ms
19,112 KB
testcase_08 AC 18 ms
14,900 KB
testcase_09 AC 16 ms
13,200 KB
testcase_10 AC 49 ms
38,540 KB
testcase_11 AC 32 ms
26,164 KB
testcase_12 AC 28 ms
21,980 KB
testcase_13 AC 12 ms
10,780 KB
testcase_14 AC 48 ms
37,604 KB
testcase_15 AC 26 ms
21,376 KB
testcase_16 AC 18 ms
15,152 KB
testcase_17 AC 30 ms
23,772 KB
testcase_18 AC 50 ms
39,040 KB
testcase_19 AC 12 ms
10,736 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 55 ms
42,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int dp[1010][10100] = {};
int y[10100];
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> y[i];
	}
	for (int i = 1; i <= n; i++) {
		int m = 1000000007;
		for (int j = 0; j <= 10010; j++) {
			dp[i][j] += abs(y[i] - j);
			if (m > dp[i - 1][j]) {
				m = dp[i - 1][j];
			}
			dp[i][j] += m;
		}
	}
	int ans = 1000000007;
	for (int i = 0; i <= 10010; i++) {
		if (ans > dp[n][i]) {
			ans = dp[n][i];
		}
	}
	cout << ans << endl;
}
0