結果

問題 No.2854 -1 Subsequence
ユーザー テナガザルテナガザル
提出日時 2024-08-25 13:53:12
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 709 bytes
コンパイル時間 1,214 ms
コンパイル使用メモリ 109,652 KB
実行使用メモリ 15,748 KB
最終ジャッジ日時 2024-08-25 13:53:18
合計ジャッジ時間 4,827 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
13,320 KB
testcase_01 AC 87 ms
13,004 KB
testcase_02 AC 91 ms
13,312 KB
testcase_03 AC 50 ms
8,704 KB
testcase_04 AC 103 ms
14,548 KB
testcase_05 AC 64 ms
10,232 KB
testcase_06 AC 35 ms
7,168 KB
testcase_07 AC 99 ms
14,112 KB
testcase_08 AC 16 ms
6,944 KB
testcase_09 AC 69 ms
11,008 KB
testcase_10 AC 112 ms
15,748 KB
testcase_11 AC 118 ms
15,696 KB
testcase_12 AC 112 ms
15,668 KB
testcase_13 AC 110 ms
15,704 KB
testcase_14 AC 110 ms
15,672 KB
testcase_15 AC 111 ms
15,728 KB
testcase_16 AC 112 ms
15,732 KB
testcase_17 AC 114 ms
15,692 KB
testcase_18 AC 112 ms
15,676 KB
testcase_19 AC 115 ms
15,688 KB
testcase_20 AC 115 ms
15,680 KB
testcase_21 AC 133 ms
15,744 KB
testcase_22 AC 106 ms
15,676 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,944 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 1 ms
6,940 KB
testcase_33 AC 1 ms
6,940 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 1 ms
6,944 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 1 ms
6,940 KB
testcase_38 AC 1 ms
6,940 KB
testcase_39 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  if (n == 1)
  {
    cout << -a[0] << endl;
    return 0;
  }
  vector<vector<long long>> dp(n + 1, vector<long long> (2, -1e18));
  dp[0][0] = 0;
  for (int i = 0; i < n; ++i)
  {
    dp[i + 1][0] = max(dp[i][0], dp[i][1] + a[i]);
    dp[i + 1][1] = max(dp[i][1], dp[i][0] - a[i]);
  }
  long long ans = max(dp[n][0], dp[n][1]);
  auto b = a;
  sort(b.rbegin(), b.rend());
  if (a == b && ans == 0)
  {
    ans = -1e18;
    for (int i = 0; i < n - 1; ++i) ans = max(ans, (long long)a[i + 1] - a[i]);
  }
  cout << ans << endl;
}
0