結果

問題 No.430 文字列検索
ユーザー masa
提出日時 2016-10-03 00:00:53
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 721 bytes
コンパイル時間 609 ms
コンパイル使用メモリ 71,244 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-10 00:06:02
合計ジャッジ時間 15,263 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 13 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	string s, c;
	int m;

	cin >> s >> m;
	int n = s.size();
	s += string(10, '?');
	int ans = 0;
	for (int i = 0; i < m; i++) {
		cin >> c;
		int nc = c.size();
		int to = 1;
		string c2 = c + c;
		for (int i = nc - 1; i > 1; i--) {
			if (c2.substr(0, i) == c2.substr(i)) {
				to = i;
				break;
			}
		}

		int pos = 0;
		while (pos < n) {
			bool ok = true;
			for (int i = 0; i < nc; i++) {
				if (c[i] != s[pos+i]) {
					ok = false;
					break;
				}
			}
			if (ok) {
				ans++;
				pos += to;
			} else {
				pos++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}
0