結果

問題 No.430 文字列検索
ユーザー bluemeganebluemegane
提出日時 2021-05-15 12:44:40
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 1,756 bytes
コンパイル時間 1,297 ms
コンパイル使用メモリ 116,184 KB
実行使用メモリ 26,260 KB
最終ジャッジ日時 2024-04-14 03:20:46
合計ジャッジ時間 25,398 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
23,856 KB
testcase_01 TLE -
testcase_02 TLE -
testcase_03 TLE -
testcase_04 AC 24 ms
25,836 KB
testcase_05 AC 24 ms
23,664 KB
testcase_06 AC 25 ms
25,712 KB
testcase_07 AC 24 ms
23,728 KB
testcase_08 AC 33 ms
25,960 KB
testcase_09 AC 25 ms
25,576 KB
testcase_10 AC 30 ms
25,820 KB
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;

class RollingHash
{
    public const ulong B = (ulong)1e9 + 7;
    public string S { get; set; }
    public int N { get; set; }
    public ulong[] Power { get; set; }
    public ulong[] Hash { get; set; }
    public RollingHash(string s)
    {
        this.S = s;
        this.N = s.Length;
        this.Power = new ulong[this.N + 1];
        this.Power[0] = 1;
        for (int i = 0; i < N; i++) this.Power[i + 1] = this.Power[i] * B;
        this.Hash = new ulong[this.N + 1];
        for (int i = 0; i < N; i++) this.Hash[i + 1] = this.Hash[i] * B + S[i];
    }
    public ulong Get(int l, int r) => this.Hash[r] - (this.Hash[l] * this.Power[r - l]);
}

public class P
{
    public string c { get; set; }
    public ulong rh { get; set; }
    public int cL { get; set; }
}

public class Hello
{
    static void Main()
    {
        var s = Console.ReadLine().Trim();
        var m = int.Parse(Console.ReadLine().Trim());
        var ps = new P[m];
        for (int i = 0; i < m; i++)
        {
            var t = Console.ReadLine().Trim();
            var tL = t.Length;
            var rh = new RollingHash(t);
            var t2 = rh.Get(0, tL);
            ps[i] = new P { c = t, cL = tL, rh = t2 };
        }
        getAns(s, m, ps);
    }
    static void getAns(string s, int m, P[] ps)
    {
        var rh = new RollingHash(s);
        var sL = s.Length;
        var p = 0;
        var count = 0;
        while (p < sL)
        {
            foreach (var x in ps)
            {
                if (p + x.cL <= sL)
                {
                    var a0 = rh.Get(p, p + x.cL);
                    if (a0 == x.rh) count++;
                }
            }
            p++;
        }
        Console.WriteLine(count);
    }
}
0