結果

問題 No.1646 Avoid Palindrome
ユーザー tonyu0tonyu0
提出日時 2021-08-13 23:30:02
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 1,291 bytes
コンパイル時間 921 ms
コンパイル使用メモリ 164,804 KB
実行使用メモリ 314,752 KB
最終ジャッジ日時 2024-04-14 20:48:48
合計ジャッジ時間 36,794 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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