結果
| 問題 | No.1077 Noelちゃんと星々4 |
| コンテスト | |
| ユーザー |
c-yan
|
| 提出日時 | 2020-06-14 12:31:30 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 580 bytes |
| 記録 | |
| コンパイル時間 | 3,075 ms |
| コンパイル使用メモリ | 197,896 KB |
| 最終ジャッジ日時 | 2025-01-11 04:14:12 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 2 |
| other | AC * 1 WA * 19 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
9 | scanf("%d", &N);
| ~~~~~^~~~~~~~~~
main.cpp:12:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
12 | scanf("%d", &Y[i]);
| ~~~~~^~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
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 = 1 << 30;
rep(j, a.size()){
chmin(t, dp[j] + abs(Y[i] - a[j]));
chmin(dp[j], t);
}
}
printf("%d\n", *min_element(dp.begin(), dp.end()));
return 0;
}
c-yan