結果
問題 |
No.2019 Digits Filling for All Substrings
|
ユーザー |
|
提出日時 | 2023-11-03 21:11:19 |
言語 | C# (.NET 8.0.404) |
結果 |
AC
|
実行時間 | 104 ms / 2,000 ms |
コード長 | 1,441 bytes |
コンパイル時間 | 16,359 ms |
コンパイル使用メモリ | 165,956 KB |
実行使用メモリ | 190,880 KB |
最終ジャッジ日時 | 2024-09-25 18:51:30 |
合計ジャッジ時間 | 12,743 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (128 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 double[] NList => ReadLine().Split().Select(double.Parse).ToArray(); static double[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var n = NN; var s = ReadLine(); var mod = 998_244_353; var ans = 0L; var dp = new long[3]; for (var i = 0; i < n; ++i) { var ndp = new long[3]; if (s[i] == '?') { ndp[0] += 4; ndp[1] += 3; ndp[2] += 3; for (var j = 0; j < 3; ++j) { ndp[j] = (ndp[j] + dp[j] * 4 % mod) % mod; ndp[(j + 1) % 3] = (ndp[(j + 1) % 3] + dp[j] * 3 % mod) % mod; ndp[(j + 2) % 3] = (ndp[(j + 2) % 3] + dp[j] * 3 % mod) % mod; } } else { ndp[(s[i] - '0') % 3] += 1; for (var j = 0; j < 3; ++j) ndp[(j + s[i] - '0') % 3] = (ndp[(j + s[i] - '0') % 3] + dp[j]) % mod; } ans = (ans + ndp[0]) % mod; dp = ndp; } WriteLine(ans); } }