結果

問題 No.1077 Noelちゃんと星々4
ユーザー cn_449cn_449
提出日時 2020-06-12 21:49:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,562 bytes
コンパイル時間 1,113 ms
コンパイル使用メモリ 113,080 KB
実行使用メモリ 82,028 KB
最終ジャッジ日時 2023-09-06 10:11:52
合計ジャッジ時間 2,465 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,688 KB
testcase_01 AC 3 ms
5,976 KB
testcase_02 AC 31 ms
60,776 KB
testcase_03 AC 35 ms
75,272 KB
testcase_04 AC 13 ms
27,988 KB
testcase_05 AC 10 ms
21,792 KB
testcase_06 AC 15 ms
32,008 KB
testcase_07 AC 17 ms
36,204 KB
testcase_08 AC 14 ms
27,932 KB
testcase_09 AC 11 ms
25,892 KB
testcase_10 AC 36 ms
75,032 KB
testcase_11 AC 25 ms
50,456 KB
testcase_12 AC 20 ms
44,328 KB
testcase_13 AC 10 ms
19,808 KB
testcase_14 AC 35 ms
72,992 KB
testcase_15 AC 21 ms
42,268 KB
testcase_16 AC 14 ms
28,072 KB
testcase_17 AC 22 ms
46,380 KB
testcase_18 AC 37 ms
77,092 KB
testcase_19 AC 10 ms
19,744 KB
testcase_20 AC 2 ms
5,548 KB
testcase_21 AC 41 ms
82,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

int dp[1010][10010], dp2[1010][10010];

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	dp[0][0] = 0;
	rep(j, 10010) dp2[0][j] = 0;
	rep(i, n) {
		rep(j, 10010) {
			dp[i + 1][j] = dp2[i][j] + abs(a[i] - j);
			if (j == 0) dp2[i + 1][j] = dp[i + 1][j];
			else dp2[i + 1][j] = min(dp2[i + 1][j - 1], dp[i + 1][j]);
		}
	}
	cout << dp2[n][10009] << '\n';
}
0