結果

問題 No.1077 Noelちゃんと星々4
ユーザー kotatsugame
提出日時 2020-06-12 21:35:34
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 409 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 68,488 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-24 04:33:54
合計ジャッジ時間 1,637 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:5:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    5 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
int N,Y,dp[2][10100];
main()
{
	cin>>N;
	int now=0;
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<10100;j++)dp[1-now][j]=1e9;
		cin>>Y;
		int K=1e9;
		for(int j=0;j<10100;j++)
		{
			K=min(K,dp[now][j]);
			dp[1-now][j]=min(dp[1-now][j],K+abs(Y-j));
		}
		now=1-now;
	}
	int ans=1e9;
	for(int j=0;j<10100;j++)ans=min(ans,dp[now][j]);
	cout<<ans<<endl;
}
0