結果
| 問題 |
No.2854 -1 Subsequence
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-09-06 07:40:39 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,040 bytes |
| コンパイル時間 | 2,046 ms |
| コンパイル使用メモリ | 139,976 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-06 07:40:44 |
| 合計ジャッジ時間 | 4,584 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 WA * 10 |
ソースコード
#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';
}