結果
問題 |
No.1646 Avoid Palindrome
|
ユーザー |
|
提出日時 | 2024-01-22 00:14:04 |
言語 | C# (.NET 8.0.404) |
結果 |
AC
|
実行時間 | 953 ms / 3,000 ms |
コード長 | 1,686 bytes |
コンパイル時間 | 7,153 ms |
コンパイル使用メモリ | 166,144 KB |
実行使用メモリ | 209,280 KB |
最終ジャッジ日時 | 2024-09-28 06:17:45 |
合計ジャッジ時間 | 34,808 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (86 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 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); } }