結果

問題 No.430 文字列検索
ユーザー _3_72__3_72_
提出日時 2019-09-24 18:29:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 936 ms / 2,000 ms
コード長 1,698 bytes
コンパイル時間 1,695 ms
コンパイル使用メモリ 172,388 KB
実行使用メモリ 4,416 KB
最終ジャッジ日時 2023-10-19 08:59:11
合計ジャッジ時間 11,850 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 926 ms
4,416 KB
testcase_02 AC 929 ms
4,416 KB
testcase_03 AC 927 ms
4,416 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 7 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 4 ms
4,348 KB
testcase_11 AC 932 ms
4,416 KB
testcase_12 AC 925 ms
4,416 KB
testcase_13 AC 929 ms
4,416 KB
testcase_14 AC 936 ms
4,416 KB
testcase_15 AC 930 ms
4,416 KB
testcase_16 AC 933 ms
4,416 KB
testcase_17 AC 933 ms
4,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
//----------------------------------------------------------------

int MOD = 998244353;
// int MOD = 1000000007;

vll table[11];
//----------------------------------------------------------------
signed main(){

	string s;
	ll m;
	cin >> s >> m;
	vector<string> c(m);
	rep(i,m)cin >> c[i];

	ll cnt = 0;
	
	ll base1 = 29;
	ll M = 1000000007;

	vll pow(s.size()+1);
	pow[0] = 1;
	vll hash1(s.size()+1,0);
	rep(i,s.size()){
		hash1[i+1] = (base1*hash1[i]%M + (s[i]-'A')+M)%M;
		pow[i+1] = pow[i]*base1%M;
	}
	rep(i,m){
		ll n = c[i].size();
		ll h2 = c[i][0]-'A';
		rep(k,n-1) h2 = (h2*base1%M + c[i][k+1]-'A'+M)%M;
		for(int j = 0;j+n <= s.size();j++){
			ll h1 = (hash1[j+n]-hash1[j]*pow[n]%M+M)%M;
			if(h1 == h2)cnt++;
		}
	}
	cout << cnt << endl;





	return 0;
}

//----------------------------------------------------------------

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2017-final.contest.atcoder.jp/tasks/ddcc2017_final_b
// rm -r -f test;oj dl https://agc038.contest.atcoder.jp/tasks/agc038_a
0