結果

問題 No.430 文字列検索
ユーザー 14番14番
提出日時 2016-11-07 20:18:16
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,065 bytes
コンパイル時間 933 ms
コンパイル使用メモリ 108,288 KB
実行使用メモリ 28,544 KB
最終ジャッジ日時 2024-05-03 22:57:47
合計ジャッジ時間 5,768 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
23,936 KB
testcase_01 AC 803 ms
23,132 KB
testcase_02 AC 63 ms
22,956 KB
testcase_03 AC 51 ms
22,960 KB
testcase_04 AC 33 ms
19,072 KB
testcase_05 AC 30 ms
18,688 KB
testcase_06 AC 34 ms
18,944 KB
testcase_07 AC 33 ms
18,944 KB
testcase_08 AC 50 ms
23,096 KB
testcase_09 AC 35 ms
18,944 KB
testcase_10 AC 41 ms
22,016 KB
testcase_11 TLE -
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.Text;
using System.Linq;
using System.Collections.Generic;

public class Program
{
    public void Proc() {
        Reader.IsDebug = false;
        string text = Reader.ReadLine();
        int mtCount = int.Parse(Reader.ReadLine());
        Dictionary<char, Dictionary<int,List<string>>> dic = new Dictionary<char, Dictionary<int, List<string>>>();
        for(int i=0; i<mtCount; i++) {
            string wrd = Reader.ReadLine();
            if(!dic.ContainsKey(wrd[0])) {
                dic.Add(wrd[0], new Dictionary<int, List<string>>());
            }
            if(!dic[wrd[0]].ContainsKey(wrd.Length)) {
                dic[wrd[0]].Add(wrd.Length, new List<string>());
            }
            
            dic[wrd[0]][wrd.Length].Add(wrd);
        }

        long ans = 0;
        for(int i=0; i<text.Length; i++) {
            if(!dic.ContainsKey(text[i])) {
                continue;
            }
            foreach(int key in dic[text[i]].Keys.OrderBy(a=>a)) {
                if(key > text.Length - i) {
                    break;
                }
                foreach(string wrd in dic[text[i]][key]) {
                    if(wrd.Equals(text.Substring(i, key))) {
                        ans++;
                        break;
                    }
                }
            }
        }
        Console.WriteLine(ans);

        
    }


    public class Reader {
        public static bool IsDebug = true;
        private static System.IO.StringReader SReader;
        private static string InitText = @"



ABAACABCAACBABABACBBAC
7
A
C
AA
ABB
ABA
BA
CBBAC


";
        public static string ReadLine() {
            if(IsDebug) {
                if(SReader == null) {
                    SReader = new System.IO.StringReader(InitText.Trim());
                }
                return SReader.ReadLine();
            } else {
                return Console.ReadLine();
            }
        }
    }
    public static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0