結果

問題 No.430 文字列検索
ユーザー masamasa
提出日時 2016-10-03 00:00:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,365 ms / 2,000 ms
コード長 721 bytes
コンパイル時間 553 ms
コンパイル使用メモリ 71,976 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-15 17:32:35
合計ジャッジ時間 11,834 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 335 ms
4,376 KB
testcase_02 AC 1,265 ms
4,380 KB
testcase_03 AC 762 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1,365 ms
4,380 KB
testcase_12 AC 1,338 ms
4,376 KB
testcase_13 AC 1,353 ms
4,376 KB
testcase_14 AC 1,327 ms
4,380 KB
testcase_15 AC 1,222 ms
4,376 KB
testcase_16 AC 782 ms
4,380 KB
testcase_17 AC 754 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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