結果

問題 No.2854 -1 Subsequence
ユーザー ryota2357ryota2357
提出日時 2024-08-24 12:27:29
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 607 bytes
コンパイル時間 801 ms
コンパイル使用メモリ 131,604 KB
実行使用メモリ 14,900 KB
最終ジャッジ日時 2024-08-24 14:32:50
合計ジャッジ時間 4,092 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
12,752 KB
testcase_01 AC 80 ms
12,064 KB
testcase_02 AC 78 ms
12,616 KB
testcase_03 AC 44 ms
8,192 KB
testcase_04 AC 85 ms
13,752 KB
testcase_05 AC 54 ms
9,856 KB
testcase_06 AC 31 ms
6,944 KB
testcase_07 AC 83 ms
13,420 KB
testcase_08 AC 12 ms
6,944 KB
testcase_09 AC 59 ms
10,496 KB
testcase_10 AC 94 ms
14,804 KB
testcase_11 AC 93 ms
14,864 KB
testcase_12 AC 94 ms
14,872 KB
testcase_13 AC 96 ms
14,772 KB
testcase_14 AC 96 ms
14,760 KB
testcase_15 AC 100 ms
14,832 KB
testcase_16 AC 94 ms
14,764 KB
testcase_17 AC 93 ms
14,840 KB
testcase_18 AC 93 ms
14,800 KB
testcase_19 AC 95 ms
14,836 KB
testcase_20 AC 93 ms
14,796 KB
testcase_21 AC 90 ms
14,824 KB
testcase_22 AC 103 ms
14,900 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 1 ms
6,940 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 1 ms
6,944 KB
testcase_31 WA -
testcase_32 AC 1 ms
6,940 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 1 ms
6,940 KB
testcase_36 AC 1 ms
6,940 KB
testcase_37 WA -
testcase_38 AC 2 ms
6,944 KB
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

constexpr int INF = 1'000'000'000 - 1;

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>(2, -INF));
	dp[0][0] = 0;
	for (int i = 0; i < n; ++i) {
		dp[i+1][1] = max({dp[i][1], dp[i][0] - a[i], -(ll)a[i]});
		dp[i+1][0] = max({dp[i][0], dp[i][1] + a[i]});
	}
	cout << max(dp[n][0], dp[n][1]) << endl;
}
0