結果

問題 No.2854 -1 Subsequence
ユーザー ryota2357ryota2357
提出日時 2024-08-20 20:03:27
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 600 bytes
コンパイル時間 1,007 ms
コンパイル使用メモリ 131,224 KB
実行使用メモリ 15,116 KB
最終ジャッジ日時 2024-08-24 14:28:31
合計ジャッジ時間 4,631 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 78 ms
12,256 KB
testcase_02 WA -
testcase_03 AC 46 ms
8,192 KB
testcase_04 WA -
testcase_05 AC 58 ms
9,728 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 101 ms
14,808 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 101 ms
14,780 KB
testcase_14 WA -
testcase_15 AC 102 ms
14,864 KB
testcase_16 WA -
testcase_17 AC 102 ms
14,908 KB
testcase_18 WA -
testcase_19 AC 101 ms
14,832 KB
testcase_20 AC 103 ms
14,800 KB
testcase_21 WA -
testcase_22 AC 109 ms
14,968 KB
testcase_23 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cassert>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	
	assert(1 <= n && n <= 200000);
	for (int i = 0; i < n; ++i) assert(abs(a[i]) <= 1000'000'000);
	
	vector<vector<ll>> dp(n+1, vector<ll>(3));
	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][2] - a[i], dp[i][0] - a[i]});
		dp[i+1][2] = max(dp[i][2], dp[i][1] + a[i]);
	}
	cout << max(dp[n][1], dp[n][2]) << endl;
}
0