結果

問題 No.1645 AB's abs
ユーザー phsplsphspls
提出日時 2022-10-03 10:37:41
言語 Rust
(1.77.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 916 bytes
コンパイル時間 2,215 ms
コンパイル使用メモリ 144,316 KB
実行使用メモリ 18,072 KB
最終ジャッジ日時 2023-08-27 06:04:20
合計ジャッジ時間 3,690 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 10 ms
9,492 KB
testcase_14 AC 7 ms
7,444 KB
testcase_15 AC 10 ms
10,016 KB
testcase_16 AC 10 ms
9,556 KB
testcase_17 AC 10 ms
10,088 KB
testcase_18 AC 9 ms
8,760 KB
testcase_19 AC 9 ms
9,512 KB
testcase_20 AC 7 ms
7,948 KB
testcase_21 AC 9 ms
8,492 KB
testcase_22 AC 9 ms
9,780 KB
testcase_23 AC 9 ms
9,552 KB
testcase_24 AC 9 ms
9,572 KB
testcase_25 AC 10 ms
10,096 KB
testcase_26 AC 9 ms
9,492 KB
testcase_27 AC 10 ms
10,080 KB
testcase_28 AC 10 ms
10,080 KB
testcase_29 AC 9 ms
9,512 KB
testcase_30 AC 11 ms
10,544 KB
testcase_31 AC 10 ms
9,760 KB
testcase_32 AC 11 ms
10,076 KB
testcase_33 AC 18 ms
16,380 KB
testcase_34 AC 17 ms
16,348 KB
testcase_35 AC 17 ms
16,392 KB
testcase_36 AC 18 ms
16,360 KB
testcase_37 AC 17 ms
16,396 KB
testcase_38 AC 17 ms
18,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

const MOD: usize = 998244353;

fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).ok();
    let a: Vec<usize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let summary = a.iter().sum::<usize>();
    let mut dp = vec![vec![0usize; 2*summary+1]; n+1];
    dp[0][summary] = 1;
    for i in 0..n {
        for j in 0..=2*summary {
            if dp[i][j] == 0 { continue; }
            dp[i+1][j-a[i]] += dp[i][j];
            dp[i+1][j+a[i]] += dp[i][j];
            dp[i+1][j-a[i]] %= MOD;
            dp[i+1][j+a[i]] %= MOD;
        }
    }
    let mut result = 0usize;
    for i in 0..=summary {
        result += i * dp[n][summary-i];
        result += i * dp[n][summary+i];
        result %= MOD;
    }
    println!("{}", result);
}
0