結果

問題 No.430 文字列検索
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-10-18 18:54:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 505 ms / 2,000 ms
コード長 816 bytes
コンパイル時間 589 ms
コンパイル使用メモリ 63,200 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-03 04:44:01
合計ジャッジ時間 6,334 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 501 ms
5,376 KB
testcase_02 AC 505 ms
5,376 KB
testcase_03 AC 501 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 502 ms
5,376 KB
testcase_12 AC 504 ms
5,376 KB
testcase_13 AC 502 ms
5,376 KB
testcase_14 AC 503 ms
5,376 KB
testcase_15 AC 501 ms
5,376 KB
testcase_16 AC 500 ms
5,376 KB
testcase_17 AC 505 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
const int INF = 1e9;
const ll mod = 1e9 + 7;

string moto;
int containt(string a){
	int ret = 0;
	if(a.size() > moto.size()) return ret;
	ll t = 1;
	rep(i, a.size()){
		t *= mod;
	}
	ll hasha = 0, hashmoto = 0;
	rep(i, a.size()){
		hasha = hasha * mod + a[i];
		hashmoto = hashmoto * mod + moto[i];
	}

	for (int i = 0; i + a.size() <= moto.size(); ++i){
		if(hasha == hashmoto) ret++;
		hashmoto= hashmoto * mod + moto[i + a.size()] - moto[i] * t;
	}
	return ret;
}

int main(void){
	cin >> moto;
	int n; cin >> n;
	int ans = 0;
	rep(i, n){
		string s; cin >> s;
		ans += containt(s);
	}
	printf("%d\n", ans);
	return 0;
}
0