結果

問題 No.1077 Noelちゃんと星々4
ユーザー chocoruskchocorusk
提出日時 2020-06-12 22:24:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 975 bytes
コンパイル時間 1,091 ms
コンパイル使用メモリ 125,996 KB
実行使用メモリ 82,624 KB
最終ジャッジ日時 2023-09-06 10:39:58
合計ジャッジ時間 2,895 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
82,340 KB
testcase_01 AC 22 ms
82,336 KB
testcase_02 AC 35 ms
82,396 KB
testcase_03 AC 40 ms
82,360 KB
testcase_04 AC 26 ms
82,448 KB
testcase_05 AC 25 ms
82,404 KB
testcase_06 AC 28 ms
82,624 KB
testcase_07 AC 29 ms
82,340 KB
testcase_08 AC 28 ms
82,464 KB
testcase_09 AC 26 ms
82,392 KB
testcase_10 AC 39 ms
82,360 KB
testcase_11 AC 33 ms
82,404 KB
testcase_12 AC 32 ms
82,340 KB
testcase_13 AC 25 ms
82,340 KB
testcase_14 AC 38 ms
82,344 KB
testcase_15 AC 30 ms
82,400 KB
testcase_16 AC 27 ms
82,340 KB
testcase_17 AC 32 ms
82,356 KB
testcase_18 AC 39 ms
82,536 KB
testcase_19 AC 26 ms
82,336 KB
testcase_20 AC 21 ms
82,448 KB
testcase_21 AC 42 ms
82,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n; cin>>n;
	int y[1010];
	for(int i=0; i<n; i++) cin>>y[i];
	ll dp[1010][10010]={};
	const int mx=10000;
	for(int i=0; i<=mx; i++) dp[0][i]=abs(y[0]-i);
	for(int i=1; i<n; i++){
		dp[i][0]=dp[i-1][0];
		for(int j=1; j<=mx; j++) dp[i][j]=min(dp[i][j-1], dp[i-1][j]);
		for(int j=0; j<=mx; j++) dp[i][j]+=abs(j-y[i]);
	}
	ll ans=1e18;
	for(int i=0; i<=mx; i++) ans=min(ans, dp[n-1][i]);
	cout<<ans<<endl;
	return 0;
}
0