結果

問題 No.430 文字列検索
ユーザー plasma_eplasma_e
提出日時 2019-01-20 17:53:46
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 227 ms / 2,000 ms
コード長 732 bytes
コンパイル時間 928 ms
コンパイル使用メモリ 103,964 KB
実行使用メモリ 26,436 KB
最終ジャッジ日時 2023-10-11 21:02:32
合計ジャッジ時間 2,610 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 227 ms
26,436 KB
testcase_02 AC 8 ms
4,348 KB
testcase_03 AC 9 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 219 ms
26,228 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 12 ms
5,716 KB
testcase_11 AC 74 ms
7,336 KB
testcase_12 AC 71 ms
7,392 KB
testcase_13 AC 75 ms
7,408 KB
testcase_14 AC 55 ms
6,100 KB
testcase_15 AC 42 ms
4,944 KB
testcase_16 AC 12 ms
4,352 KB
testcase_17 AC 10 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<set>
#include<map>
#include<string>

int main()
{
	std::string str;
	std::cin >> str;
	auto N = str.size();
	int M;
	std::cin >> M;
	int count = 0;
	std::map<std::size_t, int>hash_count;
	for (std::size_t i = 0; i < N; ++i)
	{
		std::size_t hash = 0;
		for (std::size_t k = 0; i + k < N&&k < 10; ++k)
		{
			hash *= 27;
			hash += str[i + k] - 'A' + 1;
			++hash_count[hash];
		}
	}
	for (int i = 0; i < M; ++i)
	{
		std::string C;
		std::cin >> C;
		std::size_t hash = 0;
		for (auto c : C)
		{
			hash *= 27;
			hash += c - 'A' + 1;
		}
		count += hash_count[hash];
	}
	std::cout << count << std::endl;
}
0