結果

問題 No.1766 Tatsujin Remix
ユーザー 👑 kakel-sankakel-san
提出日時 2021-11-26 23:25:45
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 2,135 bytes
コンパイル時間 2,345 ms
コンパイル使用メモリ 72,032 KB
実行使用メモリ 37,708 KB
最終ジャッジ日時 2023-09-12 05:35:59
合計ジャッジ時間 4,838 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
23,656 KB
testcase_01 AC 63 ms
23,604 KB
testcase_02 AC 63 ms
23,660 KB
testcase_03 AC 62 ms
21,720 KB
testcase_04 AC 63 ms
21,624 KB
testcase_05 AC 64 ms
21,616 KB
testcase_06 AC 64 ms
21,568 KB
testcase_07 AC 63 ms
23,600 KB
testcase_08 AC 64 ms
23,692 KB
testcase_09 AC 80 ms
30,712 KB
testcase_10 AC 80 ms
30,704 KB
testcase_11 AC 80 ms
30,560 KB
testcase_12 AC 81 ms
30,676 KB
testcase_13 AC 90 ms
37,204 KB
testcase_14 AC 93 ms
37,628 KB
testcase_15 AC 95 ms
37,512 KB
testcase_16 AC 94 ms
37,648 KB
testcase_17 AC 94 ms
37,708 KB
testcase_18 AC 93 ms
35,592 KB
testcase_19 AC 94 ms
35,636 KB
testcase_20 AC 94 ms
37,604 KB
testcase_21 AC 94 ms
35,620 KB
testcase_22 AC 94 ms
37,668 KB
testcase_23 AC 94 ms
37,676 KB
testcase_24 AC 91 ms
37,676 KB
testcase_25 AC 93 ms
35,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;

class yuki325
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static string[] SList(int n) => Enumerable.Repeat(0, n).Select(_ => ReadLine()).ToArray();
    static void Main()
    {
        var n = NN;
        var s = string.Concat(SList(n));

        var key = 998244353;
        var dp = new long[s.Length][];
        for (var i = 0; i < dp.Length; ++i) dp[i] = new long[3];

        if (s[0] == 'd') dp[0][1] = 1;
        else if (s[0] == 'k') dp[0][2] = 1;
        else
        {
            dp[0][0] = 1;
            if (s[1] != 'd') dp[0][1] = 1;
            if (s[1] != 'k') dp[0][2] = 1;
        }
        for (var i = 1; i < dp.Length; ++i)
        {
            var prevsum = (dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][2]) % key;
            if (i % 2 == 0)
            {
                if (s[i] == 'd') dp[i][1] = prevsum;
                else if (s[i] == 'k') dp[i][2] = prevsum;
                else
                {
                    dp[i][0] = dp[i - 1][0];
                    if (s[i + 1] != 'd') dp[i][1] = prevsum;
                    if (s[i + 1] != 'k') dp[i][2] = prevsum;
                }
            }
            else
            {
                var prevdk = (dp[i - 1][1] + dp[i - 1][2]) % key;
                if (s[i] == 'd') dp[i][1] = prevdk;
                else if (s[i] == 'k') dp[i][2] = prevdk;
                else
                {
                    dp[i][0] = prevsum;
                    if (i + 1 == s.Length || s[i + 1] != 'd') dp[i][1] = prevdk;
                    if (i + 1 == s.Length || s[i + 1] != 'k') dp[i][2] = prevdk;
                }
            }
        }
        //DebugTable(dp);
        WriteLine(dp[s.Length - 1].Sum() % key);
    }
    static void DebugTable<T>(T[][] table)
    {
        Console.WriteLine("{");
        foreach (var list in table) Console.WriteLine(string.Join(", ", list));
        Console.WriteLine("}");
    }
}
0