結果
| 問題 | No.430 文字列検索 |
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-11-07 19:35:20 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,828 bytes |
| 記録 | |
| コンパイル時間 | 999 ms |
| コンパイル使用メモリ | 108,928 KB |
| 実行使用メモリ | 28,288 KB |
| 最終ジャッジ日時 | 2024-11-10 00:12:33 |
| 合計ジャッジ時間 | 5,178 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | AC * 2 TLE * 1 -- * 11 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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, List<string>> dic = new Dictionary<char, List<string>>();
for(int i=0; i<mtCount; i++) {
string wrd = Reader.ReadLine();
if(!dic.ContainsKey(wrd[0])) {
dic.Add(wrd[0], new List<string>());
}
dic[wrd[0]].Add(wrd);
}
dic.ToList().ForEach(a=>a.Value.Sort((b,c)=>b.Length<c.Length?-1:b.Length>c.Length?1:0));
long ans = 0;
for(int i=0; i<text.Length; i++) {
if(!dic.ContainsKey(text[i])) {
continue;
}
foreach(string wrd in dic[text[i]]) {
if(text.Length-i<wrd.Length) {
break;
}
if(wrd.Equals(text.Substring(i, wrd.Length))) {
ans++;
}
}
}
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();
}
}
14番