結果

問題 No.430 文字列検索
ユーザー CELICACELICA
提出日時 2020-10-18 22:45:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 942 bytes
コンパイル時間 1,722 ms
コンパイル使用メモリ 173,640 KB
実行使用メモリ 7,832 KB
最終ジャッジ日時 2023-09-28 12:08:52
合計ジャッジ時間 3,122 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 48 ms
7,772 KB
testcase_02 AC 18 ms
7,704 KB
testcase_03 AC 19 ms
7,652 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 45 ms
7,712 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 38 ms
7,800 KB
testcase_12 AC 39 ms
7,804 KB
testcase_13 AC 39 ms
7,776 KB
testcase_14 AC 37 ms
7,832 KB
testcase_15 AC 33 ms
7,728 KB
testcase_16 AC 21 ms
7,776 KB
testcase_17 AC 19 ms
7,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ul = unsigned long;
using ull = unsigned long long;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	string s;
	cin >> s;

	ull ls = s.size();

	vector<vector<ull> > hs(11);
	for (ull i = 1; i <= min(ls, 10ull); ++i)
	{
		ull h{ 0 };
		for (ull j = 0; j < i; ++j)
			h = h * 26 + s[j] - 'A';

		hs[i].push_back(h);
		ull d = (ull)pow(26, i - 1);
		for (ull j = 1; j <= ls - i; ++j)
		{
			h %= d;
			h *= 26;
			h += s[j + i - 1] - 'A';
			hs[i].push_back(h);
		}

		sort(hs[i].begin(), hs[i].end());
	}

	int m;
	cin >> m;

	int res{ 0 };
	for (int i = 0; i < m; ++i)
	{
		string c;
		cin >> c;

		ull h{ 0 };
		for (ull i = 0; i < c.size(); ++i)
			h = h * 26 + c[i] - 'A';

		auto itb = hs[c.size()].begin();
		auto ite = hs[c.size()].end();

		res += upper_bound(itb, ite, h)
			- lower_bound(itb, ite, h);
	}

	cout << res << "\n";

	return 0;
}
0