結果

問題 No.430 文字列検索
ユーザー kurenai3110kurenai3110
提出日時 2016-10-03 00:36:54
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 808 bytes
コンパイル時間 723 ms
コンパイル使用メモリ 77,688 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 11:08:48
合計ジャッジ時間 19,115 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int ans;

int bm(string s, string t,int index)
{
	int n = s.size();
	int m = t.size();
	map<char, int> f;
	for (int i = 0; i<m; i++) f[t[i]] = m - 1 - i;
	int p = m - 1+index;
	while (p<n)
	{
		int k = m - 1;
		while (k >= 0 && t[k] == s[p]) { k--; p--; }
		if (k == -1) {
			ans++;
			return p + 1;
		}
		else
		{
			if (f.find(s[p]) == f.end()) p += m;
			else p += max(f[s[p]], m - k);
		}
	}
	return -1;
}

int main()
{
	string s;
	cin >> s;
	int m; cin >> m;

	for (int i = 0; i < m; i++) {
		string target; cin >> target;

		int index = 0;
		while (1) {
			index = bm(s, target, index);
			if (index == -1)break;
			index++;
		}
		
	}

	cout << ans << endl;
	return 0;
}
0