結果

問題 No.2854 -1 Subsequence
ユーザー NakLon131NakLon131
提出日時 2024-08-25 14:40:58
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,352 bytes
コンパイル時間 11,184 ms
コンパイル使用メモリ 405,404 KB
実行使用メモリ 16,548 KB
最終ジャッジ日時 2024-08-25 14:41:21
合計ジャッジ時間 13,477 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
13,632 KB
testcase_01 AC 20 ms
12,996 KB
testcase_02 AC 22 ms
13,564 KB
testcase_03 AC 12 ms
8,192 KB
testcase_04 AC 25 ms
14,932 KB
testcase_05 AC 15 ms
10,112 KB
testcase_06 AC 10 ms
6,940 KB
testcase_07 AC 23 ms
14,520 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 17 ms
11,008 KB
testcase_10 AC 27 ms
16,360 KB
testcase_11 AC 27 ms
16,336 KB
testcase_12 AC 28 ms
16,500 KB
testcase_13 AC 29 ms
16,400 KB
testcase_14 AC 27 ms
16,428 KB
testcase_15 AC 28 ms
16,356 KB
testcase_16 AC 27 ms
16,348 KB
testcase_17 AC 28 ms
16,400 KB
testcase_18 AC 29 ms
16,332 KB
testcase_19 AC 28 ms
16,384 KB
testcase_20 AC 28 ms
16,480 KB
testcase_21 AC 27 ms
16,232 KB
testcase_22 AC 29 ms
16,548 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,940 KB
testcase_31 WA -
testcase_32 AC 0 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 1 ms
6,940 KB
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
	input!{
		n: usize,
		a: [i64; n],
	}
	let mut ans = 0;

	// 全て正なら、最も小さい値を一つを最小値とする。(例外パターン。一つだけ選んでどれも負になる場合)
	if is_positive(&a) {
		ans = *a.iter().min().unwrap();
	}

	// dp[i個選択][(偶数個、奇数個)選んだ状態j] = 総和のmax
	let mut dp = vec![vec![-INF; 2]; n+1];
	dp[0][0] = 0;

	for i in 1..=n {
		// 遷移後が0のときは、a[i]
		dp[i][0] = max(dp[i-1][0], dp[i-1][1] + a[i-1]);

		// 遷移後が1のときは、a[i]*(-1)
		dp[i][1] = max(dp[i-1][1], dp[i-1][0] - a[i-1]);
	}

	println!("{}", vec![ans, dp[n][0], dp[n][1]].iter().max().unwrap());
}

fn is_positive(a: &Vec<i64>) -> bool {
	for &aa in a {
		if aa < 0 { return false;}
	}
	true
}
// const MOD17: usize = 1000000007;
// const MOD93: usize = 998244353;
const INF: i64 = 1 << 60;
// let dx = vec![!0, 0, 1, 0]; // 上左下右
// let dy = vec![0, !0, 0, 1]; // 上左下右
// let d = vec!{(!0, 0), (0, !0), (1, 0), (0, 1)}; // 上左下右
#[allow(unused)]
use proconio::{input, marker::Chars, marker::Usize1};

#[allow(unused)]
use std::{
	mem::swap,
	cmp::min, cmp::max,
	cmp::Reverse,
	collections::HashSet, collections::BTreeSet,
	collections::HashMap, collections::BTreeMap,
	collections::BinaryHeap,
	collections::VecDeque,
	iter::FromIterator,
};
0