結果
問題 | No.2854 -1 Subsequence |
ユーザー |
![]() |
提出日時 | 2024-08-25 15:12:47 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 138 ms / 2,000 ms |
コード長 | 860 bytes |
コンパイル時間 | 3,105 ms |
コンパイル使用メモリ | 252,652 KB |
実行使用メモリ | 34,580 KB |
最終ジャッジ日時 | 2024-08-25 15:12:55 |
合計ジャッジ時間 | 7,254 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 40 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define rep(i, l, r) for (int i = (int)(l); i<(int)(r); i++)#define ll long longtemplate<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}const int inf = 1e9;const ll INF = 4e18;int main() {int N; cin >> N;vector<ll> A(N);rep(i, 0, N) cin >> A[i];vector dp(N+1, vector(2, vector<ll>(2, -INF)));dp[0][0][0] = 0;rep(i, 0, N) {rep(f, 0, 2) rep(j, 0, 2) {if (j == 0) {chmax(dp[i+1][1][1-j], dp[i][f][j] - A[i]);}else {chmax(dp[i+1][1][1-j], dp[i][f][j] + A[i]);}chmax(dp[i+1][f][j], dp[i][f][j]);}}cout << max(dp[N][1][0], dp[N][1][1]) << endl;}