結果

問題 No.2019 Digits Filling for All Substrings
ユーザー 👑 kakel-sankakel-san
提出日時 2023-11-03 21:11:19
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 1,441 bytes
コンパイル時間 7,449 ms
コンパイル使用メモリ 158,580 KB
実行使用メモリ 182,364 KB
最終ジャッジ日時 2023-11-03 21:11:42
合計ジャッジ時間 12,263 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
30,876 KB
testcase_01 AC 53 ms
30,900 KB
testcase_02 AC 54 ms
30,924 KB
testcase_03 AC 53 ms
30,932 KB
testcase_04 AC 77 ms
37,964 KB
testcase_05 AC 70 ms
35,916 KB
testcase_06 AC 67 ms
35,328 KB
testcase_07 AC 64 ms
34,172 KB
testcase_08 AC 86 ms
41,384 KB
testcase_09 AC 89 ms
41,452 KB
testcase_10 AC 94 ms
41,452 KB
testcase_11 AC 90 ms
41,452 KB
testcase_12 AC 88 ms
41,452 KB
testcase_13 AC 95 ms
41,452 KB
testcase_14 AC 51 ms
31,004 KB
testcase_15 AC 52 ms
31,012 KB
testcase_16 AC 56 ms
31,704 KB
testcase_17 AC 52 ms
31,044 KB
testcase_18 AC 52 ms
31,068 KB
testcase_19 AC 50 ms
30,924 KB
testcase_20 AC 51 ms
30,924 KB
testcase_21 AC 51 ms
30,924 KB
testcase_22 AC 51 ms
30,924 KB
testcase_23 AC 54 ms
30,924 KB
testcase_24 AC 78 ms
35,688 KB
testcase_25 AC 90 ms
37,668 KB
testcase_26 AC 72 ms
34,256 KB
testcase_27 AC 56 ms
31,940 KB
testcase_28 AC 58 ms
31,916 KB
testcase_29 AC 81 ms
37,068 KB
testcase_30 AC 91 ms
39,568 KB
testcase_31 AC 91 ms
39,340 KB
testcase_32 AC 67 ms
33,540 KB
testcase_33 AC 82 ms
182,364 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (100 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 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);
    }
}
0