結果
問題 | No.1239 Multiplication -2 |
ユーザー | phspls |
提出日時 | 2022-11-19 15:03:37 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 47 ms / 2,000 ms |
コード長 | 1,861 bytes |
コンパイル時間 | 14,532 ms |
コンパイル使用メモリ | 378,224 KB |
実行使用メモリ | 22,656 KB |
最終ジャッジ日時 | 2024-09-20 15:14:19 |
合計ジャッジ時間 | 15,969 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 1 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 1 ms
5,376 KB |
testcase_12 | AC | 1 ms
5,376 KB |
testcase_13 | AC | 1 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 15 ms
8,320 KB |
testcase_16 | AC | 24 ms
12,768 KB |
testcase_17 | AC | 39 ms
22,448 KB |
testcase_18 | AC | 40 ms
22,656 KB |
testcase_19 | AC | 40 ms
22,528 KB |
testcase_20 | AC | 41 ms
22,656 KB |
testcase_21 | AC | 39 ms
22,076 KB |
testcase_22 | AC | 38 ms
21,248 KB |
testcase_23 | AC | 30 ms
16,384 KB |
testcase_24 | AC | 29 ms
15,872 KB |
testcase_25 | AC | 25 ms
13,952 KB |
testcase_26 | AC | 25 ms
14,976 KB |
testcase_27 | AC | 12 ms
7,296 KB |
testcase_28 | AC | 36 ms
19,576 KB |
testcase_29 | AC | 41 ms
21,120 KB |
testcase_30 | AC | 19 ms
9,984 KB |
testcase_31 | AC | 27 ms
14,056 KB |
testcase_32 | AC | 47 ms
22,496 KB |
testcase_33 | AC | 32 ms
16,128 KB |
testcase_34 | AC | 30 ms
15,104 KB |
testcase_35 | AC | 16 ms
8,448 KB |
testcase_36 | AC | 14 ms
7,680 KB |
ソースコード
const OFFSET: usize = 2; const MOD: usize = 998244353; fn power(base: usize, times: usize) -> usize { if times == 0 { return 1usize; } if times == 1 { return base; } let temp = power(base, times/2); temp * temp % MOD * power(base, times%2) % MOD } 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<isize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut p2s = vec![1usize; n]; for i in (1..n-1).rev() { p2s[i-1] = p2s[i] * 2 % MOD; } let mut dp = vec![vec![0usize; 6]; n+1]; dp[0][OFFSET+1] = 1; let mut result = 0usize; for i in 0..n { for j in -2..=3 { let jidx = OFFSET as isize + j; let jidx = jidx as usize; if a[i].abs() * j.abs() > 2 { dp[i+1][5] += dp[i][jidx]; dp[i+1][5] %= MOD; continue; } let njidx = OFFSET as isize + a[i] * j; let njidx = njidx as usize; dp[i+1][njidx] += dp[i][jidx]; dp[i+1][njidx] %= MOD; if njidx == 0 { result += dp[i][jidx] * p2s[i]; result %= MOD; } } if i == 0 { continue; } for j in -2..=3 { let jidx = OFFSET as isize + j; let jidx = jidx as usize; let njidx = OFFSET as isize + a[i]; let njidx = njidx as usize; dp[i+1][njidx] += dp[i][jidx]; dp[i+1][njidx] %= MOD; if njidx == 0 { result += dp[i][jidx] * p2s[i]; result %= MOD; } } } println!("{}", result * power(power(2, MOD-2), n-1) % MOD); }