結果

問題 No.1077 Noelちゃんと星々4
ユーザー tkmst201tkmst201
提出日時 2021-01-29 11:56:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,299 bytes
コンパイル時間 2,837 ms
コンパイル使用メモリ 207,688 KB
実行使用メモリ 7,164 KB
最終ジャッジ日時 2023-09-09 06:41:04
合計ジャッジ時間 6,370 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 AC 2 ms
4,380 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 2 ms
4,380 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 1 ms
4,376 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	vector A(N, 0);
	REP(i, N) scanf("%d", &A[i]);
	
	auto compress = [](auto &&v, auto &&cv) -> void {
		for (auto &&u : v) cv.emplace_back(u);
		std::sort(std::begin(cv), std::end(cv));
		cv.erase(std::unique(std::begin(cv), std::end(cv)), std::end(cv));
		for (auto &&u : v) u = std::lower_bound(std::begin(cv), std::end(cv), u) - std::begin(cv);
	};
	
	vector<int> cx;
	compress(A, cx);
	
	vector dp(N, vector<int>(cx.size(), INF));
	REP(i, cx.size()) dp[0][i] = abs(cx[A[0]] - cx[i]);
	FOR(i, 1, N) {
		int mn = INF;
		REP(j, N) {
			chmin(mn, dp[i - 1][j]);
			dp[i][j] = mn + abs(cx[j] - cx[A[i]]);
		}
	}
	
	cout << *min_element(ALL(dp[N - 1])) << endl;
}
0