結果
問題 |
No.1077 Noelちゃんと星々4
|
ユーザー |
![]() |
提出日時 | 2020-06-14 12:33:00 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 574 bytes |
コンパイル時間 | 2,668 ms |
コンパイル使用メモリ | 197,504 KB |
最終ジャッジ日時 | 2025-01-11 04:14:21 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
コンパイルメッセージ
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])); dp[j] = t; } } printf("%d\n", *min_element(dp.begin(), dp.end())); return 0; }