結果

問題 No.1077 Noelちゃんと星々4
ユーザー nanophoto12nanophoto12
提出日時 2020-07-24 13:45:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 1,079 bytes
コンパイル時間 2,248 ms
コンパイル使用メモリ 204,648 KB
実行使用メモリ 81,368 KB
最終ジャッジ日時 2023-09-07 07:06:45
合計ジャッジ時間 4,517 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 63 ms
56,612 KB
testcase_03 AC 79 ms
72,504 KB
testcase_04 AC 25 ms
23,988 KB
testcase_05 AC 19 ms
18,996 KB
testcase_06 AC 31 ms
30,208 KB
testcase_07 AC 36 ms
34,488 KB
testcase_08 AC 26 ms
25,764 KB
testcase_09 AC 24 ms
22,688 KB
testcase_10 AC 80 ms
72,672 KB
testcase_11 AC 53 ms
47,904 KB
testcase_12 AC 44 ms
39,916 KB
testcase_13 AC 19 ms
17,756 KB
testcase_14 AC 78 ms
71,168 KB
testcase_15 AC 42 ms
38,916 KB
testcase_16 AC 28 ms
26,628 KB
testcase_17 AC 48 ms
43,800 KB
testcase_18 AC 81 ms
74,036 KB
testcase_19 AC 17 ms
17,328 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 89 ms
81,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

const ll mod = 1000000007;

template<typename T>
void chmin(T & ref, const T  value) {
	if (ref > value) ref = value;
}

int main() {
	int n;
	cin >> n;
	vector<ll> vs(n);
	rep(i, n) cin >> vs[i];
	vector<vector<ll>> dp(n + 1, vector<ll>(1e4 + 1, INF));
	dp[0][0] = 0;
	rep(i, n) {
		const ll v = vs[i];
		vector<ll> lows = dp[i];
		rep(j, 1e4) {
			lows[j + 1] = min(lows[j + 1], lows[j]);
		}
		rep(j, 1e4 + 1) {
			if (j <= v) {
				chmin(dp[i + 1][j], lows[j] + v- j );
			}
			else {
				chmin(dp[i + 1][j], dp[i][j] + j - v);
			}
		}
	}
	ll low = INF;
	rep(j, 1e4 + 1) {
		chmin(low, dp[n][j]);
	}
	cout << low << endl;
	return 0;
}
0