結果

問題 No.1646 Avoid Palindrome
ユーザー phsplsphspls
提出日時 2022-10-31 22:06:22
言語 Rust
(1.77.0)
結果
AC  
実行時間 336 ms / 3,000 ms
コード長 1,603 bytes
コンパイル時間 3,428 ms
コンパイル使用メモリ 137,528 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 18:50:52
合計ジャッジ時間 13,302 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 247 ms
4,380 KB
testcase_05 AC 248 ms
4,380 KB
testcase_06 AC 239 ms
4,380 KB
testcase_07 AC 247 ms
4,380 KB
testcase_08 AC 251 ms
4,376 KB
testcase_09 AC 236 ms
4,380 KB
testcase_10 AC 243 ms
4,376 KB
testcase_11 AC 237 ms
4,380 KB
testcase_12 AC 248 ms
4,376 KB
testcase_13 AC 250 ms
4,376 KB
testcase_14 AC 305 ms
4,376 KB
testcase_15 AC 314 ms
4,376 KB
testcase_16 AC 306 ms
4,384 KB
testcase_17 AC 323 ms
4,380 KB
testcase_18 AC 314 ms
4,376 KB
testcase_19 AC 310 ms
4,380 KB
testcase_20 AC 315 ms
4,380 KB
testcase_21 AC 317 ms
4,376 KB
testcase_22 AC 306 ms
4,380 KB
testcase_23 AC 322 ms
4,376 KB
testcase_24 AC 336 ms
4,376 KB
testcase_25 AC 333 ms
4,380 KB
testcase_26 AC 330 ms
4,376 KB
testcase_27 AC 333 ms
4,376 KB
testcase_28 AC 333 ms
4,380 KB
testcase_29 AC 211 ms
4,380 KB
testcase_30 AC 212 ms
4,376 KB
testcase_31 AC 210 ms
4,380 KB
testcase_32 AC 213 ms
4,384 KB
testcase_33 AC 211 ms
4,376 KB
testcase_34 AC 334 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 1 ms
4,380 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,380 KB
testcase_43 AC 211 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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<_>>();

    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 psum = vec![0usize; SIZE+1];
            for pprev in 0..=SIZE {
                for prev in 0..=SIZE {
                    if pprev == prev && prev < SIZE { continue; }
                    psum[prev] += dp[prev][pprev];
                }
            }
            for cur in 0..SIZE {
                for prev in 0..=SIZE {
                    if cur == prev { continue; }
                    next_dp[cur][prev] = psum[prev] - dp[prev][cur];
                }
            }
        } else {
            let cur = s[i] as usize - 'a' as usize;
            for pprev in 0..=SIZE {
                if pprev == cur { continue; }
                for prev in 0..=SIZE {
                    if prev == cur { continue; }
                    next_dp[cur][prev] += dp[prev][pprev];
                }
            }
        }
        for cur in 0..=SIZE {
            for prev in 0..=SIZE {
                next_dp[cur][prev] %= MOD;
            }
        }
        dp = next_dp;
    }
    println!("{}", (0..=SIZE).map(|i| (0..=SIZE).map(|j| dp[i][j]).sum::<usize>()).sum::<usize>() % MOD);
}
0