結果
問題 | No.430 文字列検索 |
ユーザー |
|
提出日時 | 2016-10-03 00:11:43 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 806 ms / 2,000 ms |
コード長 | 1,157 bytes |
コンパイル時間 | 3,695 ms |
コンパイル使用メモリ | 79,860 KB |
実行使用メモリ | 78,696 KB |
最終ジャッジ日時 | 2024-11-10 00:06:29 |
合計ジャッジ時間 | 12,084 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 14 |
ソースコード
import java.io.PrintStream;import java.util.HashMap;import java.util.Scanner;public class Y430 {Y430() throws Exception {Scanner in = new Scanner(System.in);PrintStream out = new PrintStream(System.out);String s = in.next();int m = in.nextInt();String[] w = new String[m];for (int i = 0; i < m; i++) {w[i] = in.next();}HashMap<Long, Integer>[] hashMap = new HashMap[11];for (int i = 0; i < 11; i++) {hashMap[i] = new HashMap();}for (int i = 0; i < s.length(); i++) {for (int j = 1; j <= 10 && i + j <= s.length(); j++) {Long x = encode(s.substring(i, i+j));Integer g = hashMap[j].get(x);if (g == null) g = 0;g += 1;hashMap[j].put(x, g);}}int answer = 0;for (int i = 0; i < m; i++) {Long x = encode(w[i]);Integer g = hashMap[w[i].length()].get(x);if (g != null) answer += g;}out.println(answer);}long encode(String s) {long x = 0;for (int i = 0; i < s.length(); i++) {x = x * 26 + (int)s.charAt(i) - 'A';}return x;}public static void main(String argv[]) throws Exception {new Y430();}}