結果

問題 No.1646 Avoid Palindrome
ユーザー 👑 kakel-sankakel-san
提出日時 2024-01-22 00:14:04
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 1,005 ms / 3,000 ms
コード長 1,686 bytes
コンパイル時間 15,668 ms
コンパイル使用メモリ 158,200 KB
実行使用メモリ 203,888 KB
最終ジャッジ日時 2024-01-22 00:14:57
合計ジャッジ時間 37,260 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
32,548 KB
testcase_01 AC 71 ms
32,548 KB
testcase_02 AC 71 ms
32,548 KB
testcase_03 AC 73 ms
32,932 KB
testcase_04 AC 776 ms
56,356 KB
testcase_05 AC 744 ms
56,356 KB
testcase_06 AC 740 ms
56,356 KB
testcase_07 AC 767 ms
56,356 KB
testcase_08 AC 747 ms
56,356 KB
testcase_09 AC 733 ms
56,356 KB
testcase_10 AC 739 ms
56,356 KB
testcase_11 AC 747 ms
56,356 KB
testcase_12 AC 760 ms
56,356 KB
testcase_13 AC 758 ms
56,356 KB
testcase_14 AC 916 ms
56,356 KB
testcase_15 AC 922 ms
56,356 KB
testcase_16 AC 912 ms
56,356 KB
testcase_17 AC 928 ms
56,356 KB
testcase_18 AC 936 ms
56,356 KB
testcase_19 AC 918 ms
56,356 KB
testcase_20 AC 950 ms
56,356 KB
testcase_21 AC 938 ms
56,356 KB
testcase_22 AC 926 ms
56,356 KB
testcase_23 AC 964 ms
56,356 KB
testcase_24 AC 976 ms
56,356 KB
testcase_25 AC 996 ms
56,356 KB
testcase_26 AC 973 ms
56,356 KB
testcase_27 AC 999 ms
56,356 KB
testcase_28 AC 1,005 ms
56,356 KB
testcase_29 AC 690 ms
56,356 KB
testcase_30 AC 707 ms
56,356 KB
testcase_31 AC 691 ms
56,356 KB
testcase_32 AC 683 ms
56,356 KB
testcase_33 AC 702 ms
56,356 KB
testcase_34 AC 973 ms
56,356 KB
testcase_35 AC 72 ms
32,036 KB
testcase_36 AC 73 ms
32,036 KB
testcase_37 AC 73 ms
32,036 KB
testcase_38 AC 72 ms
32,036 KB
testcase_39 AC 72 ms
32,036 KB
testcase_40 AC 73 ms
32,036 KB
testcase_41 AC 76 ms
32,548 KB
testcase_42 AC 75 ms
32,548 KB
testcase_43 AC 712 ms
203,888 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (102 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 sum = new long[26];
            for (var j = 0; j < dp.Length; ++j) sum[j % 26] = (sum[j % 26] + dp[j]) % mod;
            var ndp = new long[dp.Length];
            for (var j = 0; j < dp.Length; ++j)
            {
                var x = j / 26;
                var y = j % 26;
                if (x == y) continue;
                if (s[i] == '?' || s[i] - 'a' == y) ndp[j] = (sum[x] - dp[y * 26 + x] + mod) % mod;
            }
            dp = ndp;
        }
        WriteLine(dp.Sum() % mod);
    }
}
0