結果
問題 | No.838 Noelちゃんと星々3 |
ユーザー | MarcusAureliusAntoninus |
提出日時 | 2019-06-14 22:20:45 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 41 ms / 2,000 ms |
コード長 | 413 bytes |
コンパイル時間 | 2,033 ms |
コンパイル使用メモリ | 198,772 KB |
最終ジャッジ日時 | 2025-01-07 04:33:35 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:8:36: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 2 has type ‘long int*’ [-Wformat=] 8 | for (auto& e: Y) scanf("%lld", &e); | ~~~^ ~~ | | | | | long int* | long long int* | %ld main.cpp:18:20: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type’ {aka ‘long int’} [-Wformat=] 18 | printf("%lld\n", dp.back()); | ~~~^ ~~~~~~~~~ | | | | | __gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type {aka long int} | long long int | %ld main.cpp:6:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 6 | scanf("%d", &N); | ~~~~~^~~~~~~~~~ main.cpp:8:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 8 | for (auto& e: Y) scanf("%lld", &e); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> int main() { int N; scanf("%d", &N); std::vector<int64_t> Y(N); for (auto& e: Y) scanf("%lld", &e); std::sort(Y.begin(), Y.end()); std::vector<int64_t> dp(N + 1); dp[1] = 1ll << 60; for (int i{1}; i < N; i++) { dp[i + 1] = dp[i - 1] + Y[i] - Y[i - 1]; if (i > 1) dp[i + 1] = std::min(dp[i + 1], dp[i - 2] + Y[i] - Y[i - 2]); } printf("%lld\n", dp.back()); return 0; }