結果
問題 | No.430 文字列検索 |
ユーザー | YoshiRyu |
提出日時 | 2016-11-10 16:04:56 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 238 ms / 2,000 ms |
コード長 | 2,851 bytes |
コンパイル時間 | 3,198 ms |
コンパイル使用メモリ | 109,436 KB |
実行使用メモリ | 64,836 KB |
最終ジャッジ日時 | 2023-08-16 17:34:24 |
合計ジャッジ時間 | 7,163 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 53 ms
21,352 KB |
testcase_01 | AC | 238 ms
64,836 KB |
testcase_02 | AC | 190 ms
26,792 KB |
testcase_03 | AC | 199 ms
26,808 KB |
testcase_04 | AC | 55 ms
21,492 KB |
testcase_05 | AC | 53 ms
23,588 KB |
testcase_06 | AC | 55 ms
21,536 KB |
testcase_07 | AC | 53 ms
21,424 KB |
testcase_08 | AC | 232 ms
62,468 KB |
testcase_09 | AC | 62 ms
21,748 KB |
testcase_10 | AC | 66 ms
24,064 KB |
testcase_11 | AC | 219 ms
32,548 KB |
testcase_12 | AC | 215 ms
34,576 KB |
testcase_13 | AC | 215 ms
34,592 KB |
testcase_14 | AC | 214 ms
29,652 KB |
testcase_15 | AC | 208 ms
29,200 KB |
testcase_16 | AC | 194 ms
28,892 KB |
testcase_17 | AC | 229 ms
30,852 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.IO; using System.Linq; public class YukiCoder { public static void Solve() { var S = MyConsole.String(); var M = MyConsole.Int(); string[] MM = new string[M]; for (int i = 0 ; i < M ; i++) MM[i] = MyConsole.String(); var dic = new Dictionary<string, int>(); int sLength = S.Length; for (int sLen = 0 ; sLen < sLength ; sLen++) { string s = ""; // 検索の文字列1から10桁で一文字ずつズラしながら // 文字列をくり抜いてディクショナリに格納する for (int mLen = 1 ; mLen < 11 ; mLen++) { // 現在位置から後ろの文字を結合させながらディクショナリに追加する int j = sLen - mLen + 1; if (j < 0) break; s = S[j] + s; // ディクショナリに対して、重複した文字列は登場回数をインクリメント、新規は追加 if (dic.ContainsKey( s )) dic[s]++; else dic.Add( s, 1 ); } } int ANS = 0; // 与えられた検索対象の文字列をキーに登場回数を取得して加算を行う for (int i = 0 ; i < M ; i++) if (dic.ContainsKey( MM[i] )) ANS += dic[MM[i]]; MyConsole.wLine( ANS.ToString() ); } public static void Main() { MyConsole.Read(); Solve(); MyConsole.Finish(); } } public static class MyConsole { private static List<string> ReadedLine = new List<string>(); private static char[] buf = new char[1024]; private static int i; public static void Read() { string sr = Console.In.ReadToEnd(); ReadedLine = sr.Split( new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries ).ToList(); Console.SetOut( new StreamWriter( Console.OpenStandardOutput() ) { AutoFlush = false } ); } public static string String() { return ReadedLine[i++]; } public static string[] StringSplit() { return ReadedLine[i++].Split( new[] { ' ' } ); } public static int Int() { return int.Parse( ReadedLine[i++] ); } public static int[] IntSplit() { string[] strs = StringSplit(); int[] ret = new int[strs.Length]; for (int i = 0 ; i < strs.Length ; i++) { ret[i] = int.Parse( strs[i] ); } return ret; } public static long Long() { return long.Parse( ReadedLine[i++] ); } public static double Double() { return double.Parse( ReadedLine[i++] ); } public static void wLine( string output = null ) { Console.WriteLine( output ); } public static void Finish() { Console.Out.Flush(); } }