結果
問題 |
No.1077 Noelちゃんと星々4
|
ユーザー |
![]() |
提出日時 | 2020-06-14 12:37:38 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 601 bytes |
コンパイル時間 | 2,423 ms |
コンパイル使用メモリ | 199,440 KB |
最終ジャッジ日時 | 2025-01-11 04:14:53 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:10:19: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 2 has type ‘int*’ [-Wformat=] 10 | scanf("%lld", &N); | ~~~^ ~~ | | | | | int* | long long int* | %d main.cpp:10:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 10 | scanf("%lld", &N); | ~~~~~^~~~~~~~~~~~ main.cpp:13:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 13 | scanf("%lld", &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 ll = long long; using namespace std; int main() { int N; scanf("%lld", &N); vector<ll> Y(N), a(N); rep(i, N) { scanf("%lld", &Y[i]); a[i] = Y[i]; } sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); vector<ll> dp(a.size(), 0); rep(i, N){ ll t = 1LL << 60; rep(j, a.size()){ chmin(t, dp[j] + abs(Y[i] - a[j])); dp[j] = t; } } printf("%lld\n", *min_element(dp.begin(), dp.end())); return 0; }