結果
| 問題 |
No.1645 AB's abs
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-13 22:27:05 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 30 ms / 2,000 ms |
| コード長 | 1,072 bytes |
| コンパイル時間 | 13,020 ms |
| コンパイル使用メモリ | 401,940 KB |
| 実行使用メモリ | 18,176 KB |
| 最終ジャッジ日時 | 2024-10-03 20:03:28 |
| 合計ジャッジ時間 | 15,213 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
コンパイルメッセージ
warning: variable `S` should have a snake case name --> src/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
ソースコード
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);
}