結果

問題 No.1645 AB's abs
ユーザー tonyu0tonyu0
提出日時 2021-08-13 22:27:05
言語 Rust
(1.77.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,072 bytes
コンパイル時間 893 ms
コンパイル使用メモリ 173,856 KB
実行使用メモリ 18,176 KB
最終ジャッジ日時 2024-04-14 18:41:43
合計ジャッジ時間 3,126 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 4 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 5 ms
6,940 KB
testcase_09 AC 6 ms
6,940 KB
testcase_10 AC 4 ms
6,940 KB
testcase_11 AC 4 ms
6,944 KB
testcase_12 AC 5 ms
6,944 KB
testcase_13 AC 28 ms
17,280 KB
testcase_14 AC 25 ms
15,488 KB
testcase_15 AC 28 ms
17,152 KB
testcase_16 AC 26 ms
16,256 KB
testcase_17 AC 27 ms
17,152 KB
testcase_18 AC 25 ms
15,744 KB
testcase_19 AC 27 ms
17,280 KB
testcase_20 AC 23 ms
14,976 KB
testcase_21 AC 25 ms
16,256 KB
testcase_22 AC 27 ms
17,024 KB
testcase_23 AC 29 ms
18,048 KB
testcase_24 AC 29 ms
18,048 KB
testcase_25 AC 29 ms
18,048 KB
testcase_26 AC 29 ms
18,048 KB
testcase_27 AC 29 ms
18,048 KB
testcase_28 AC 29 ms
18,048 KB
testcase_29 AC 29 ms
18,048 KB
testcase_30 AC 29 ms
18,048 KB
testcase_31 AC 29 ms
18,048 KB
testcase_32 AC 29 ms
17,920 KB
testcase_33 AC 29 ms
18,048 KB
testcase_34 AC 29 ms
18,048 KB
testcase_35 AC 29 ms
18,176 KB
testcase_36 AC 29 ms
18,048 KB
testcase_37 AC 29 ms
17,920 KB
testcase_38 AC 29 ms
18,176 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable `S` should have a snake case name
  --> main.rs:12:9
   |
12 |     let S = n * 101;
   |         ^ help: convert the identifier to snake case (notice the capitalization): `s`
   |
   = note: `#[warn(non_snake_case)]` on by default

warning: 1 warning emitted

ソースコード

diff #

use std::io::*;
const MOD: i64 = 998244353;
fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<i32> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let S = n * 101;
    let mut dp: Vec<Vec<i64>> = vec![vec![0; S * 2]; n + 1];
    dp[0][S] = 1;
    for i in 0..n {
        for j in 0..S * 2 {
            let plus: i32 = j as i32 + a[i];
            let minus: i32 = j as i32 - a[i];
            if plus < S as i32 * 2 {
                dp[i + 1][plus as usize] += dp[i][j];
                dp[i + 1][plus as usize] %= MOD;
            }
            if 0 < minus {
                dp[i + 1][minus as usize] += dp[i][j];
                dp[i + 1][minus as usize] %= MOD;
            }
        }
    }

    let mut ans = 0i64;
    for i in 0..S * 2 {
        ans += dp[n][i] * (S as i64 - i as i64).abs() % MOD;
        ans %= MOD;
    }
    println!("{}", ans);
}
0