結果

問題 No.1077 Noelちゃんと星々4
ユーザー mamimume____momamimume____mo
提出日時 2020-07-08 01:14:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 906 bytes
コンパイル時間 842 ms
コンパイル使用メモリ 89,716 KB
実行使用メモリ 81,536 KB
最終ジャッジ日時 2024-04-09 22:52:45
合計ジャッジ時間 2,571 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 55 ms
56,960 KB
testcase_03 AC 69 ms
72,832 KB
testcase_04 AC 22 ms
24,192 KB
testcase_05 AC 17 ms
18,944 KB
testcase_06 AC 28 ms
30,464 KB
testcase_07 AC 32 ms
34,688 KB
testcase_08 AC 24 ms
25,984 KB
testcase_09 AC 21 ms
22,784 KB
testcase_10 AC 69 ms
72,832 KB
testcase_11 AC 44 ms
48,256 KB
testcase_12 AC 37 ms
40,448 KB
testcase_13 AC 15 ms
18,176 KB
testcase_14 AC 67 ms
71,296 KB
testcase_15 AC 36 ms
39,168 KB
testcase_16 AC 24 ms
26,752 KB
testcase_17 AC 40 ms
44,032 KB
testcase_18 AC 69 ms
74,240 KB
testcase_19 AC 15 ms
17,408 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 77 ms
81,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int n;
	cin >> n;
	vector<ll> y(n);
	for(int i = 0;i < n;i++)cin >> y[i];

	vector<vector<ll>> dp(n+1,vector<ll>(10002,0));
	//dp[i][j]:=i番目までを講義単調増加にしたとき,i番目がj以下であるときの最小コスト

	for(int i = 0;i < n;i++){
		for(int j = 0;j <= 10001;j++){
			dp[i+1][j] = abs(y[i] - (ll)j) + dp[i][j];
		}
		for(int j = 1;j <= 10001;j++){
			dp[i+1][j] = min(dp[i+1][j],dp[i+1][j-1]);
		}
	}

	cout << dp[n][10001] << endl;
}
0