結果

問題 No.2854 -1 Subsequence
ユーザー takumi152takumi152
提出日時 2024-08-25 16:04:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 769 bytes
コンパイル時間 1,130 ms
コンパイル使用メモリ 106,160 KB
実行使用メモリ 15,784 KB
最終ジャッジ日時 2024-08-25 16:04:37
合計ジャッジ時間 3,801 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
13,364 KB
testcase_01 AC 34 ms
12,844 KB
testcase_02 AC 35 ms
13,184 KB
testcase_03 AC 20 ms
8,704 KB
testcase_04 AC 40 ms
14,464 KB
testcase_05 AC 26 ms
10,240 KB
testcase_06 AC 15 ms
7,168 KB
testcase_07 AC 38 ms
14,216 KB
testcase_08 AC 8 ms
6,940 KB
testcase_09 AC 28 ms
10,984 KB
testcase_10 AC 45 ms
15,720 KB
testcase_11 AC 44 ms
15,784 KB
testcase_12 AC 43 ms
15,756 KB
testcase_13 AC 44 ms
15,744 KB
testcase_14 AC 44 ms
15,640 KB
testcase_15 AC 44 ms
15,696 KB
testcase_16 AC 44 ms
15,628 KB
testcase_17 AC 43 ms
15,768 KB
testcase_18 AC 43 ms
15,676 KB
testcase_19 AC 44 ms
15,564 KB
testcase_20 AC 43 ms
15,604 KB
testcase_21 AC 42 ms
15,696 KB
testcase_22 AC 44 ms
15,692 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 AC 2 ms
6,940 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 2 ms
6,944 KB
testcase_35 AC 2 ms
6,944 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 2 ms
6,944 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 998244353;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<ll> a(n);
  for (auto &x: a) cin >> x;

  vector<vector<ll>> dp(n + 1, vector<ll>(3, (ll) -1e18));
  dp[0][0] = 0;
  for (int i = 0; i < n; i++)
  {
    dp[i+1][0] = dp[i][0];
    dp[i+1][1] = max(dp[i][1], max(dp[i][0] - a[i], dp[i][2] - a[i]));
    dp[i+1][2] = max(dp[i][2], dp[i][1] + a[i]);
  }

  ll ans = max(dp[n][1], dp[n][2]);

  cout << ans << endl;

  return 0;
}
0