結果
| 問題 | 
                            No.1646 Avoid Palindrome
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2024-01-21 20:46:05 | 
| 言語 | C#  (.NET 8.0.404)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,664 bytes | 
| コンパイル時間 | 8,645 ms | 
| コンパイル使用メモリ | 168,440 KB | 
| 実行使用メモリ | 60,160 KB | 
| 最終ジャッジ日時 | 2024-09-28 06:15:43 | 
| 合計ジャッジ時間 | 12,184 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | TLE * 1 -- * 39 | 
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (112 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var n = NN;
        var s = ReadLine();
        if (n == 1)
        {
            if (s[0] == '?') WriteLine(26);
            else WriteLine(1);
            return;
        }
        if (n == 2)
        {
            if (s[0] == '?' && s[1] == '?') WriteLine(26 * 25);
            else if (s[0] == '?' || s[1] == '?') WriteLine(25);
            else if (s[0] == s[1]) WriteLine(0);
            else WriteLine(1);
            return;
        }
        var dp = new long[26 * 26];
        for (var i = 0; i < 26; ++i) for (var j = 0; j < 26; ++j)
        {
            if (i == j) continue;
            if ((s[0] == '?' || s[0] - 'a' == i) && (s[1] == '?' || s[1] - 'a' == j)) dp[i * 26 + j] = 1;
        }
        var mod = 998_244_353;
        for (var i = 2; i < n; ++i)
        {
            var ndp = new long[dp.Length];
            for (var j = 0; j < dp.Length; ++j)
            {
                var x = j / 26;
                var y = j % 26;
                for (var z = 0; z < 26; ++z)
                {
                    if (x == z || y == z) continue;
                    if (s[i] == '?' || s[i] - 'a' == z) ndp[y * 26 + z] = (ndp[y * 26 + z] + dp[j]) % mod;
                }
            }
            dp = ndp;
        }
        WriteLine(dp.Sum() % mod);
    }
}