結果

問題 No.1646 Avoid Palindrome
ユーザー 👑 kakel-sankakel-san
提出日時 2024-01-21 20:46:05
言語 C#
(.NET 8.0.203)
結果
TLE  
実行時間 -
コード長 1,664 bytes
コンパイル時間 6,990 ms
コンパイル使用メモリ 158,832 KB
実行使用メモリ 62,648 KB
最終ジャッジ日時 2024-01-21 20:46:18
合計ジャッジ時間 12,889 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
36,260 KB
testcase_01 AC 76 ms
39,736 KB
testcase_02 AC 77 ms
32,932 KB
testcase_03 AC 81 ms
32,932 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (94 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

diff #

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);
    }
}
0