結果

問題 No.1077 Noelちゃんと星々4
ユーザー 👑 jupirojupiro
提出日時 2020-06-12 21:37:25
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 238 ms / 2,000 ms
コード長 1,584 bytes
コンパイル時間 1,208 ms
コンパイル使用メモリ 131,664 KB
実行使用メモリ 239,376 KB
最終ジャッジ日時 2023-09-06 09:56:40
合計ジャッジ時間 4,564 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,620 KB
testcase_01 AC 4 ms
5,740 KB
testcase_02 AC 166 ms
164,932 KB
testcase_03 AC 210 ms
212,852 KB
testcase_04 AC 67 ms
66,196 KB
testcase_05 AC 50 ms
50,308 KB
testcase_06 AC 85 ms
85,104 KB
testcase_07 AC 97 ms
97,668 KB
testcase_08 AC 72 ms
71,776 KB
testcase_09 AC 60 ms
62,000 KB
testcase_10 AC 213 ms
213,188 KB
testcase_11 AC 140 ms
138,716 KB
testcase_12 AC 116 ms
114,724 KB
testcase_13 AC 47 ms
47,916 KB
testcase_14 AC 213 ms
208,148 KB
testcase_15 AC 114 ms
111,104 KB
testcase_16 AC 74 ms
73,548 KB
testcase_17 AC 128 ms
125,560 KB
testcase_18 AC 217 ms
216,964 KB
testcase_19 AC 45 ms
45,760 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 238 ms
239,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	ll n; scanf("%lld", &n);
	const ll offset = 10000;
	const ll mx = 30000;
	vector<vector<ll>> dp(n, vector<ll>(mx + 1, INF));
	vector<ll> y(n); for (int i = 0; i < n; i++) scanf("%lld", &y[i]), y[i] += offset;
	for (int i = 0; i <= mx; i++) dp[0][i] = llabs(i - y[0]);
	for (int i = 1; i < n; i++) {
		ll mn = INF;
		for (int j = 0; j <= mx; j++) {
			chmin(mn, dp[i - 1][j]);
			chmin(dp[i][j], mn + llabs(y[i] - j));
		}
	}
	ll res = INF;
	for (int i = 0; i <= mx; i++) chmin(res, dp[n - 1][i]);
	cout << res << endl;
	return 0;
}
0