結果
| 問題 | 
                            No.1077 Noelちゃんと星々4
                             | 
                    
| コンテスト | |
| ユーザー | 
                             c-yan
                         | 
                    
| 提出日時 | 2020-06-14 10:02:59 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 4 ms / 2,000 ms | 
| コード長 | 500 bytes | 
| コンパイル時間 | 2,495 ms | 
| コンパイル使用メモリ | 199,812 KB | 
| 最終ジャッジ日時 | 2025-01-11 04:12:18 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 20 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:8:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |         scanf("%d", &N);
      |         ~~~~~^~~~~~~~~~
main.cpp:11:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |                 scanf("%d", &Y[i]);
      |                 ~~~~~^~~~~~~~~~~~~
            
            ソースコード
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
using namespace std;
int main()
{
	int N;
	scanf("%d", &N);
	vector<int> Y(N), a(N);
	rep(i, N) {
		scanf("%d", &Y[i]);
		a[i] = Y[i];
	}
	sort(a.begin(), a.end());
	a.erase(unique(a.begin(), a.end()), a.end());
	vector<int> dp(a.size(), 0);
	rep(i, N){
		int t = dp[0];
		rep(j, a.size()){
			t = min(t, dp[j]);
			dp[j] = t + abs(Y[i] - a[j]);
		}
	}
	printf("%d\n", *min_element(dp.begin(), dp.end()));
	return 0;
}
            
            
            
        
            
c-yan