結果

問題 No.2219 Re:010
ユーザー kakel-sankakel-san
提出日時 2023-08-26 20:28:02
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,648 bytes
コンパイル時間 2,845 ms
コンパイル使用メモリ 105,088 KB
実行使用メモリ 24,576 KB
最終ジャッジ日時 2024-12-25 22:30:00
合計ジャッジ時間 3,989 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

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