結果

問題 No.1646 Avoid Palindrome
ユーザー tonyu0
提出日時 2021-08-13 23:30:02
言語 Rust
(1.83.0 + proconio)
結果
TLE  
実行時間 -
コード長 1,291 bytes
コンパイル時間 13,893 ms
コンパイル使用メモリ 402,728 KB
実行使用メモリ 314,624 KB
最終ジャッジ日時 2024-10-03 23:35:14
合計ジャッジ時間 49,027 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 1 TLE * 10 -- * 29
権限があれば一括ダウンロードができます

ソースコード

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 s: Vec<char> = itr.next().unwrap().chars().collect();

    let mut dp: Vec<Vec<Vec<i64>>> = vec![vec![vec![0; 27]; 27]; n + 1];
    dp[0][26][26] = 1;
    for i in 0..n {
        for j in 0..=26 {
            for k in 0..=26 {
                if s[i] == '?' {
                    for l in 0..26 {
                        if l == j || l == k {
                            continue;
                        }
                        dp[i + 1][l][j] += dp[i][j][k];
                        dp[i + 1][l][j] %= MOD;
                    }
                } else {
                    let c = (s[i] as u8 - 'a' as u8) as usize;
                    if c == j || c == k {
                        continue;
                    }
                    dp[i + 1][c][j] += dp[i][j][k];
                    dp[i + 1][c][j] %= MOD;
                }
            }
        }
    }

    let mut ans = 0i64;
    for i in 0..26 {
        for j in 0..26 {
            ans += dp[n][i][j];
            ans %= MOD;
        }
    }
    println!("{}", ans);
}
0