結果
| 問題 | 
                            No.1077 Noelちゃんと星々4
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2020-06-12 22:10:30 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 60 ms / 2,000 ms | 
| コード長 | 487 bytes | 
| コンパイル時間 | 2,667 ms | 
| コンパイル使用メモリ | 193,260 KB | 
| 最終ジャッジ日時 | 2025-01-11 02:37:17 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 20 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         int n; scanf("%d",&n);
      |                ~~~~~^~~~~~~~~
main.cpp:12:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         rep(i,n) scanf("%d",&a[i]);
      |                  ~~~~~^~~~~~~~~~~~
            
            ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int INF=1<<29;
int main(){
	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);
	static int dp[1000][10001];
	rep(i,n) rep(j,10001) dp[i][j]=INF;
	rep(j,10001) dp[0][j]=abs(a[0]-j);
	rep(i,n-1){
		int mn=INF;
		rep(j,10001){
			mn=min(mn,dp[i][j]);
			dp[i+1][j]=min(dp[i+1][j],mn+abs(a[i+1]-j));
		}
	}
	printf("%d\n",*min_element(dp[n-1],dp[n-1]+10001));
	return 0;
}