結果

問題 No.2854 -1 Subsequence
ユーザー saisai
提出日時 2024-08-25 14:00:02
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 647 bytes
コンパイル時間 2,706 ms
コンパイル使用メモリ 251,944 KB
実行使用メモリ 7,936 KB
最終ジャッジ日時 2024-08-25 14:00:09
合計ジャッジ時間 4,632 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
7,040 KB
testcase_01 AC 23 ms
6,944 KB
testcase_02 AC 23 ms
7,040 KB
testcase_03 AC 13 ms
6,940 KB
testcase_04 AC 26 ms
7,296 KB
testcase_05 AC 17 ms
6,940 KB
testcase_06 AC 11 ms
6,940 KB
testcase_07 AC 25 ms
7,296 KB
testcase_08 AC 5 ms
6,944 KB
testcase_09 AC 19 ms
6,940 KB
testcase_10 AC 28 ms
7,936 KB
testcase_11 AC 28 ms
7,936 KB
testcase_12 AC 26 ms
7,936 KB
testcase_13 AC 27 ms
7,936 KB
testcase_14 AC 28 ms
7,936 KB
testcase_15 AC 27 ms
7,936 KB
testcase_16 AC 26 ms
7,936 KB
testcase_17 AC 28 ms
7,936 KB
testcase_18 AC 26 ms
7,808 KB
testcase_19 AC 27 ms
7,936 KB
testcase_20 AC 27 ms
7,808 KB
testcase_21 AC 25 ms
7,808 KB
testcase_22 AC 29 ms
7,936 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
6,940 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 1 ms
6,940 KB
testcase_31 WA -
testcase_32 AC 2 ms
6,944 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 WA -
testcase_38 AC 2 ms
6,944 KB
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

void solve() {
  int N; std::cin >> N;
  std::vector<long long> A(N);
  for (auto &a : A) std::cin >> a;
  std::vector<long long> dp[2];
  const long long INF = (1LL<<60);
  for (int i = 0; i < 2; i++) dp[i].resize(N+1, -INF);
  dp[0][0] = 0;
  for (int i = 1; i <= N; i++) {
    dp[0][i] = std::max(dp[0][i-1], dp[1][i-1]+A[i-1]);
    dp[1][i] = std::max(dp[1][i-1], dp[0][i-1]-A[i-1]);
  }
  std::cout << std::max(dp[1][N], dp[0][N]) << std::endl;
}

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

  int testcases = 1;
  //std::cin >> testcases;
  for (;testcases--;) solve();

  return 0;
}
0