結果

問題 No.430 文字列検索
ユーザー ttkkggwwttkkggww
提出日時 2024-05-31 17:05:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 898 bytes
コンパイル時間 4,527 ms
コンパイル使用メモリ 272,864 KB
実行使用メモリ 20,864 KB
最終ジャッジ日時 2024-08-15 16:46:29
合計ジャッジ時間 5,175 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 207 ms
20,864 KB
testcase_03 AC 7 ms
6,940 KB
testcase_04 AC 6 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 209 ms
20,608 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 12 ms
6,944 KB
testcase_12 AC 48 ms
6,940 KB
testcase_13 AC 47 ms
6,940 KB
testcase_14 AC 47 ms
6,944 KB
testcase_15 AC 37 ms
6,940 KB
testcase_16 AC 28 ms
6,940 KB
testcase_17 AC 9 ms
6,944 KB
testcase_18 AC 8 ms
6,940 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;

	map<int,int> mp;
	for(int l = 1;l<11;l++){
		mint hashS = 0;
		for(int i = 0;i<l;i++){
			hashS = hashS*base + S[i];
		}
		for(int i = 0;i+l<=S.size();i++){
			mp[hashS.val()]++;
			if(i+l<S.size()) hashS = hashS*base + S[i+l] - coef[l]*S[i];
		}
	}

	int ans = 0;
	for(int i = 0;i<M;i++){
		mint hashT = 0;
		for(int j = 0;j<T[i].size();j++){
			hashT = hashT*base + T[i][j];
		}
		ans += mp[hashT.val()];
	}
	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