結果

問題 No.430 文字列検索
ユーザー ttkkggwwttkkggww
提出日時 2024-05-31 17:01:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 896 bytes
コンパイル時間 4,519 ms
コンパイル使用メモリ 267,960 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-31 17:01:46
合計ジャッジ時間 25,701 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1,979 ms
6,944 KB
testcase_02 TLE -
testcase_03 TLE -
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 9 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 6 ms
6,940 KB
testcase_11 AC 1,989 ms
6,948 KB
testcase_12 AC 1,982 ms
6,944 KB
testcase_13 AC 1,949 ms
6,944 KB
testcase_14 AC 1,956 ms
6,940 KB
testcase_15 AC 1,941 ms
6,944 KB
testcase_16 AC 1,916 ms
6,940 KB
testcase_17 AC 1,944 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;
string S;
using mint = modint998244353;
int M;
vector<string> T;

void solve(){
	ll base = 314;
	vector<mint> coef(S.size() );
	coef[0] = 1;
	for(int i = 1;i<S.size();i++) coef[i] = coef[i-1] * base;


	int ans = 0;
	for(int i = 0;i<M;i++){
		if(S.size() < T[i].size()) continue;
		mint hashT = 0;
		mint hashS = 0;
		for(int j = 0;j<T[i].size();j++){
			hashT = hashT*base + T[i][j];
			hashS = hashS*base + S[j];
		}
		if(hashT == hashS) ans++;
		for(int j = 0;j<S.size()-T[i].size();j++){
			hashS = hashS * base + S[j+T[i].size()];
			hashS -= coef[T[i].size()] * S[j];
			if(hashT == hashS) ans++;
		}
	}
	cout<<ans<<endl;

	
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> S >> M;
	T.resize(M);
	for(int i = 0; i < M; ++i) cin >> T[i];
	solve();
}

0