結果

問題 No.2172 SEARCH in the Text Editor
ユーザー 👑 kakel-sankakel-san
提出日時 2023-10-16 21:52:20
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 1,051 ms / 2,000 ms
コード長 3,779 bytes
コンパイル時間 17,562 ms
コンパイル使用メモリ 159,828 KB
実行使用メモリ 190,316 KB
最終ジャッジ日時 2023-10-16 21:52:54
合計ジャッジ時間 32,705 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
32,452 KB
testcase_01 AC 77 ms
32,472 KB
testcase_02 AC 74 ms
32,428 KB
testcase_03 AC 1,051 ms
62,408 KB
testcase_04 AC 250 ms
62,408 KB
testcase_05 AC 281 ms
62,336 KB
testcase_06 AC 113 ms
46,924 KB
testcase_07 AC 129 ms
47,472 KB
testcase_08 AC 120 ms
48,324 KB
testcase_09 AC 138 ms
55,748 KB
testcase_10 AC 135 ms
54,216 KB
testcase_11 AC 111 ms
45,516 KB
testcase_12 AC 137 ms
54,320 KB
testcase_13 AC 172 ms
61,844 KB
testcase_14 AC 174 ms
62,008 KB
testcase_15 AC 119 ms
48,260 KB
testcase_16 AC 118 ms
49,124 KB
testcase_17 AC 133 ms
53,080 KB
testcase_18 AC 176 ms
62,000 KB
testcase_19 AC 179 ms
61,844 KB
testcase_20 AC 120 ms
48,000 KB
testcase_21 AC 191 ms
62,064 KB
testcase_22 AC 186 ms
60,940 KB
testcase_23 AC 188 ms
60,728 KB
testcase_24 AC 193 ms
60,892 KB
testcase_25 AC 189 ms
60,652 KB
testcase_26 AC 352 ms
61,968 KB
testcase_27 AC 316 ms
61,908 KB
testcase_28 AC 204 ms
61,832 KB
testcase_29 AC 196 ms
61,840 KB
testcase_30 AC 186 ms
61,840 KB
testcase_31 AC 212 ms
61,848 KB
testcase_32 AC 174 ms
62,004 KB
testcase_33 AC 172 ms
62,004 KB
testcase_34 AC 191 ms
60,728 KB
testcase_35 AC 191 ms
60,788 KB
testcase_36 AC 192 ms
60,652 KB
testcase_37 AC 213 ms
60,652 KB
testcase_38 AC 249 ms
61,920 KB
testcase_39 AC 270 ms
61,996 KB
testcase_40 AC 190 ms
61,840 KB
testcase_41 AC 194 ms
61,896 KB
testcase_42 AC 185 ms
61,848 KB
testcase_43 AC 210 ms
61,840 KB
testcase_44 AC 190 ms
62,060 KB
testcase_45 AC 173 ms
62,060 KB
testcase_46 AC 125 ms
51,252 KB
testcase_47 AC 113 ms
46,308 KB
testcase_48 AC 115 ms
47,080 KB
testcase_49 AC 140 ms
56,848 KB
testcase_50 AC 148 ms
55,248 KB
testcase_51 AC 113 ms
190,316 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (108 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
/home/judge/data/code/Main.cs(97,16): warning CS0414: フィールド 'Program.mod' が割り当てられていますが、値は使用されていません [/home/judge/data/code/main.csproj]
  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 int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var n = NN;
        var t = ReadLine();
        var list = new Pair[n];
        var mod = 998_244_353;
        for (var i = 0; i < n; ++i)
        {
            var s = ReadLine();
            if (s[0] == '~')
            {
                var c = s.Split();
                var a = int.Parse(c[1]) - 1;
                var b = int.Parse(c[2]) - 1;
                if (list[a].IsShort && list[b].IsShort)
                {
                    var u = list[a].Left.Concat(list[b].Left).ToArray();
                    if (u.Length < t.Length)
                    {
                        list[i] = new Pair(u.ToArray(), u.ToArray(), true, 0);
                    }
                    else
                    {
                        list[i] = new Pair(u.Take(t.Length - 1).ToArray(),
                            u.Skip(u.Length - t.Length + 1).ToArray(), false, Count(t, u));
                    }
                }
                else if (list[a].IsShort)
                {
                    var u = list[a].Left.Concat(list[b].Left).ToArray();
                    list[i] = new Pair(u.Take(t.Length - 1).ToArray(),
                        list[b].Right, false, (list[b].Count + Count(t, u)) % mod);
                }
                else if (list[b].IsShort)
                {
                    var u = list[a].Right.Concat(list[b].Left).ToArray();
                    list[i] = new Pair(list[a].Left,
                        u.Skip(u.Length - t.Length + 1).ToArray(), false, (list[a].Count + Count(t, u)) % mod);
                }
                else
                {
                    var u = list[a].Right.Concat(list[b].Left).ToArray();
                    list[i] = new Pair(list[a].Left, list[b].Right, false, (list[a].Count + list[b].Count + Count(t, u)) % mod);
                }
            }
            else
            {
                if (s.Length < t.Length)
                {
                    list[i] = new Pair(s.ToCharArray(), s.ToCharArray(), true, 0);
                }
                else //if (t.Length > 1)
                {
                    list[i] = new Pair(s.Take(t.Length - 1).ToArray(),
                        s.Skip(s.Length - t.Length + 1).ToArray(), false, Count(t, s.ToCharArray()));
                }
                // else
                // {
                //     list[i] = new Pair(Array.Empty<char>(), Array.Empty<char>(), false, Count(t, s.ToArray()));
                // }
            }
        }
        WriteLine(list[n - 1].Count);
    }
    static int Count(string t, char[] u)
    {
        var ans = 0;
        for (var i = 0; i + t.Length <= u.Length; ++i)
        {
            var flg = true;
            for (var j = 0; j < t.Length; ++j)
            {
                if (t[j] != u[i + j])
                {
                    flg = false;
                    break;
                }
            }
            if (flg) ++ans;
        }
        return ans;
    }
    static int mod = 998_244_353;
    class Pair
    {
        public char[] Left;
        public char[] Right;
        public bool IsShort;
        public long Count;
        public Pair(char[] l, char[] r, bool i, long c)
        {
            Left = l; Right = r; IsShort = i; Count = c;
        }
    }
}
0