結果

問題 No.1646 Avoid Palindrome
ユーザー phsplsphspls
提出日時 2022-10-17 11:38:06
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,539 bytes
コンパイル時間 4,241 ms
コンパイル使用メモリ 143,552 KB
実行使用メモリ 5,256 KB
最終ジャッジ日時 2023-09-10 11:00:23
合計ジャッジ時間 13,224 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 296 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

const MOD: usize = 998244353;
const SIZE: usize = 26;

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

    let mut dp = vec![vec![0usize; SIZE+1]; SIZE+1];
    dp[SIZE][SIZE] = 1;
    for i in 0..n {
        let mut next_dp = vec![vec![0usize; SIZE+1]; SIZE+1];
        if s[i] == '?' {
            let mut summary = vec![0usize; SIZE+1];
            for pprev in 0..=SIZE {
                for prev in 0..=SIZE {
                    summary[prev] += dp[prev][pprev];
                    summary[prev] %= MOD;
                }
            }
            for prev in 0..=SIZE {
                for cur in 0..SIZE {
                    if prev == cur { continue; }
                    next_dp[cur][prev] = MOD + summary[prev] - dp[prev][cur];
                    next_dp[cur][prev] %= MOD;
                }
            }
        } else {
            let cur = s[i] as usize - 'a' as usize;
            for pprev in 0..=SIZE {
                if cur == pprev { continue; }
                for prev in 0..=SIZE {
                    if cur == prev { continue; }
                    next_dp[cur][prev] += dp[pprev][prev];
                    next_dp[cur][prev] %= MOD;
                }
            }
        }
        dp = next_dp;
    }

    println!("{}", dp.iter().map(|v| v.iter().sum::<usize>()).sum::<usize>() % MOD);
}
0