結果

問題 No.1077 Noelちゃんと星々4
ユーザー okok
提出日時 2020-06-12 21:34:56
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 466 ms / 2,000 ms
コード長 1,033 bytes
コンパイル時間 1,040 ms
コンパイル使用メモリ 88,064 KB
実行使用メモリ 5,848 KB
最終ジャッジ日時 2023-09-06 09:54:52
合計ジャッジ時間 6,598 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,608 KB
testcase_01 AC 9 ms
5,628 KB
testcase_02 AC 319 ms
5,608 KB
testcase_03 AC 405 ms
5,748 KB
testcase_04 AC 125 ms
5,620 KB
testcase_05 AC 95 ms
5,656 KB
testcase_06 AC 161 ms
5,684 KB
testcase_07 AC 188 ms
5,744 KB
testcase_08 AC 137 ms
5,608 KB
testcase_09 AC 117 ms
5,848 KB
testcase_10 AC 411 ms
5,676 KB
testcase_11 AC 268 ms
5,660 KB
testcase_12 AC 221 ms
5,660 KB
testcase_13 AC 91 ms
5,736 KB
testcase_14 AC 406 ms
5,664 KB
testcase_15 AC 213 ms
5,624 KB
testcase_16 AC 140 ms
5,668 KB
testcase_17 AC 240 ms
5,596 KB
testcase_18 AC 420 ms
5,748 KB
testcase_19 AC 86 ms
5,676 KB
testcase_20 AC 4 ms
5,624 KB
testcase_21 AC 466 ms
5,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	const int offset = 2000;
	const int MAX = 110000 + offset;
	int N;
	vector<int> Y;
	vector<vector<int>> dp;
	
	cin>>N;
	
	Y.resize(N);
	dp.resize(2, vector<int>(MAX, INF));
	
	
	for(int i = 0; i < N; i++){
		cin>>Y[i];
		
		Y[i] += offset;
	}
	
	for(int i = 0; i < MAX; i++){
		dp[0][i] = 0;
	}
	
	for(int i = 0; i < N; i++){
		for(int j = 0; j < MAX; j++){
			dp[(i+1)%2][j] = min(dp[(i+1)%2][j], dp[(i)%2][j] + abs(Y[i] - j));
		}
		
		for(int j = 0; j < MAX; j++){
			if(j) dp[(i+1)%2][j] = min(dp[(i+1)%2][j-1], dp[(i+1)%2][j]);
			dp[i%2][j] = INF;
		}
	}
	
	cout<<dp[N%2][MAX-1]<<endl;
	
	return 0;
}
0