結果

問題 No.430 文字列検索
ユーザー noriocnorioc
提出日時 2016-10-03 00:11:57
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 1,411 bytes
コンパイル時間 5,202 ms
コンパイル使用メモリ 101,300 KB
実行使用メモリ 25,196 KB
最終ジャッジ日時 2023-08-13 18:24:40
合計ジャッジ時間 6,128 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return Console.ReadLine().Split(); }

    static int Calc(string s, List<string> xs) {
        var ss = new List<int>[26];
        for (int i = 0; i < ss.Length; i++)
            ss[i] = new List<int>();

        for (int i = 0; i < s.Length; i++) {
            ss[s[i] - 'A'].Add(i);
        }

        int ans = 0;
        for (int i = 0; i < xs.Count; i++) {
            var t = xs[i];

            foreach (var p in ss[t[0] - 'A']) {
                bool ok = true;
                for (int j = 0; j < t.Length; j++) {
                    if (p + j < s.Length && s[p + j] == t[j]) {
                        // ok
                    }
                    else {
                        ok = false;
                        break;
                    }
                }

                if (ok) ans++;
            }
        }
        return ans;
    }

    static void Main() {
        var s = Console.ReadLine();
        int m = ReadInt();
        var xs = new List<string>();
        for (int i = 0; i < m; i++)
            xs.Add(Console.ReadLine());

        var ans = Calc(s, xs);
        Console.WriteLine(ans);
    }
}
0