結果

問題 No.1077 Noelちゃんと星々4
ユーザー c-yanc-yan
提出日時 2020-06-14 10:09:45
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 518 bytes
コンパイル時間 2,403 ms
コンパイル使用メモリ 197,764 KB
最終ジャッジ日時 2025-01-11 04:12:45
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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]);
      |                 ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#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()){
			if (dp[j] < t) {
				t = dp[j];
			}
			dp[j] = t + abs(Y[i] - a[j]);
		}
	}
	printf("%d\n", *min_element(dp.begin(), dp.end()));
	return 0;
}
0