結果
問題 | No.2854 -1 Subsequence |
ユーザー | VvyLw |
提出日時 | 2024-09-06 07:41:31 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 39 ms / 2,000 ms |
コード長 | 1,041 bytes |
コンパイル時間 | 2,116 ms |
コンパイル使用メモリ | 139,848 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-06 07:41:36 |
合計ジャッジ時間 | 4,469 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 40 |
ソースコード
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #ifdef local #include <C++/core/io/debug_print.hpp> #else #define dump(...) void(0); #endif #include <iostream> #include <valarray> #include <limits> #include <ranges> namespace man { constexpr inline void chmax(int64_t &a, const int64_t b) noexcept { if(a < b) { a = b; } } } int main() { std::cin.tie(nullptr) -> sync_with_stdio(false); int n; std::cin >> n; std::valarray<int> a(n); for(auto &e: a) { std::cin >> e; } std::valarray<int64_t> dp(2); dp[1] = std::numeric_limits<int>::min(); for(const auto &i: std::views::iota(0, n)) { std::valarray ndp = dp; man::chmax(ndp[0], dp[0]); man::chmax(ndp[0], dp[1] + a[i]); man::chmax(ndp[1], dp[1]); man::chmax(ndp[1], dp[0] - a[i]); dp.swap(ndp); } dump(dp); const auto ret = dp.max(); if(ret == 0) { std::cout << -a.min() << '\n'; std::exit(0); } std::cout << ret << '\n'; }