結果

問題 No.430 文字列検索
ユーザー plasma_eplasma_e
提出日時 2019-01-20 17:44:40
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 789 bytes
コンパイル時間 1,228 ms
コンパイル使用メモリ 96,632 KB
実行使用メモリ 7,648 KB
最終ジャッジ日時 2023-10-11 21:02:26
合計ジャッジ時間 5,440 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
権限があれば一括ダウンロードができます

ソースコード

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;
	for (int i = 0; i < M; ++i)
	{
		std::string C;
		std::cin >> C;
		std::size_t bhash = 0;
		std::size_t mod = 1;
		for (auto c : C)
		{
			bhash *= 26;
			bhash += c - 'A';
			mod *= 26;
		}
		std::size_t hash = 0;
		for (std::size_t k = 0; k < C.size() - 1; ++k)
		{
			hash *= 26;
			hash += str[k] - 'A';
		}
		for (std::size_t k = C.size() - 1; k < N; ++k)
		{
			hash *= 26;
			hash += str[k] - 'A';
			hash %= mod;
			if (hash == bhash)
			{
				++count;
			}
		}
	}
	std::cout << count << std::endl;
}
0