結果

問題 No.1077 Noelちゃんと星々4
ユーザー 沙耶花沙耶花
提出日時 2020-06-12 21:26:42
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 647 bytes
コンパイル時間 2,041 ms
コンパイル使用メモリ 202,172 KB
実行使用メモリ 81,120 KB
最終ジャッジ日時 2023-09-06 09:45:01
合計ジャッジ時間 4,006 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 69 ms
56,672 KB
testcase_03 AC 89 ms
72,404 KB
testcase_04 AC 28 ms
23,936 KB
testcase_05 AC 21 ms
18,656 KB
testcase_06 AC 35 ms
30,208 KB
testcase_07 AC 41 ms
34,432 KB
testcase_08 AC 30 ms
25,780 KB
testcase_09 AC 26 ms
22,712 KB
testcase_10 AC 89 ms
72,448 KB
testcase_11 AC 59 ms
47,868 KB
testcase_12 AC 49 ms
40,036 KB
testcase_13 AC 21 ms
17,808 KB
testcase_14 AC 88 ms
70,928 KB
testcase_15 AC 47 ms
38,900 KB
testcase_16 AC 31 ms
26,256 KB
testcase_17 AC 53 ms
43,708 KB
testcase_18 AC 91 ms
73,776 KB
testcase_19 AC 20 ms
17,320 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 100 ms
81,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000005



int main(){
	
	int N;
	cin>>N;
	
	vector<int> Y(N);
	for(int i=0;i<N;i++){
		cin>>Y[i];
		Y[i] += 3000;
	}
	
	vector<vector<int>> dp(N,vector<int>(20000,Inf));
	for(int i=0;i<N;i++){
		int mini = Inf;
		for(int j=0;j<20000;j++){
			if(i==0){
				dp[i][j] = abs(Y[i]-j);
			}
			else{
				mini = min(mini,dp[i-1][j]);
				dp[i][j] = min(dp[i][j],mini+abs(Y[i]-j));
			}
		}
	}
	
	int ans = Inf;
	for(int i=0;i<dp.back().size();i++)ans = min(ans,dp.back()[i]);
	
	cout<<ans<<endl;
	
	return 0;
}
0