結果

問題 No.2219 Re:010
ユーザー 👑 kakel-sankakel-san
提出日時 2023-08-26 20:28:02
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,648 bytes
コンパイル時間 1,615 ms
コンパイル使用メモリ 63,992 KB
実行使用メモリ 29,880 KB
最終ジャッジ日時 2023-08-26 20:28:06
合計ジャッジ時間 4,482 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
23,312 KB
testcase_01 AC 52 ms
23,444 KB
testcase_02 AC 51 ms
21,280 KB
testcase_03 AC 70 ms
28,820 KB
testcase_04 AC 54 ms
21,480 KB
testcase_05 AC 63 ms
27,484 KB
testcase_06 AC 55 ms
21,992 KB
testcase_07 AC 58 ms
23,744 KB
testcase_08 AC 64 ms
26,360 KB
testcase_09 AC 63 ms
26,276 KB
testcase_10 AC 63 ms
27,056 KB
testcase_11 AC 59 ms
24,284 KB
testcase_12 AC 59 ms
24,328 KB
testcase_13 AC 66 ms
27,764 KB
testcase_14 AC 67 ms
29,880 KB
testcase_15 AC 67 ms
27,704 KB
testcase_16 AC 67 ms
27,872 KB
testcase_17 AC 71 ms
27,544 KB
testcase_18 AC 65 ms
29,772 KB
testcase_19 AC 62 ms
25,744 KB
testcase_20 AC 69 ms
27,768 KB
testcase_21 AC 51 ms
21,184 KB
testcase_22 AC 52 ms
21,220 KB
testcase_23 AC 51 ms
19,268 KB
権限があれば一括ダウンロードができます

ソースコード

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 s = ReadLine();
        WriteLine(Count010(s));
    }
    static long Count010(string s)
    {
        var mod = 998_244_353;
        var dp = new long[3][];
        for (var i = 0; i < dp.Length; ++i) dp[i] = new long[s.Length];
        var count = new long[s.Length];
        count[0] = s[0] == '?' ? 2 : 1;
        if (s[0] != '1') dp[0][0] = 1;
        for (var i = 1; i < s.Length; ++i)
        {
            if (s[i] == '0')
            {
                dp[0][i] = (dp[0][i - 1] + count[i - 1]) % mod;
                dp[1][i] = dp[1][i - 1];
                dp[2][i] = (dp[2][i - 1] + dp[1][i - 1]) % mod;
                count[i] = count[i - 1];
            }
            else if (s[i] == '1')
            {
                dp[0][i] = dp[0][i - 1];
                dp[1][i] = (dp[1][i - 1] + dp[0][i - 1]) % mod;
                dp[2][i] = dp[2][i - 1];
                count[i] = count[i - 1];
            }
            else
            {
                dp[0][i] = (dp[0][i - 1] * 2 + count[i - 1]) % mod;
                dp[1][i] = (dp[1][i - 1] * 2 + dp[0][i - 1]) % mod;
                dp[2][i] = (dp[2][i - 1] * 2 + dp[1][i - 1]) % mod;
                count[i] = count[i - 1] * 2 % mod;
            }
        }
        return dp[2].Last();
    }
}
0