結果

問題 No.430 文字列検索
ユーザー masamasa
提出日時 2016-10-02 23:43:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 698 bytes
コンパイル時間 607 ms
コンパイル使用メモリ 71,448 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 10:55:50
合計ジャッジ時間 13,156 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
		for (int i = nc - 1; i > 1; i--) {
			if (c.substr(0, i) == c.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