結果

問題 No.430 文字列検索
ユーザー plasma_e
提出日時 2019-01-20 17:31:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,375 ms / 2,000 ms
コード長 734 bytes
コンパイル時間 665 ms
コンパイル使用メモリ 95,424 KB
最終ジャッジ日時 2025-01-06 20:30:47
ジャッジサーバーID
(参考情報)
judge3 / judge4
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

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();
	std::vector<std::size_t> start[26];
	for (std::size_t i = 0; i < N; ++i)
	{
		start[str[i] - 'A'].emplace_back(i);
	}
	int M;
	std::cin >> M;
	int count = 0;
	for (int i = 0; i < M; ++i)
	{
		std::string C;
		std::cin >> C;
		for (auto s : start[C[0] - 'A'])
		{
			if (s + C.size() <= N)
			{
				++count;
				for (std::size_t k = 1; k < C.size() && s + k < N; ++k)
				{
					if (C[k] != str[k + s])
					{
						--count;
						break;
					}
				}
			}
		}
	}
	std::cout << count << std::endl;
}
0