結果

問題 No.430 文字列検索
ユーザー _3_72__3_72_
提出日時 2019-09-24 17:40:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 352 ms / 2,000 ms
コード長 1,886 bytes
コンパイル時間 1,698 ms
コンパイル使用メモリ 172,964 KB
実行使用メモリ 7,776 KB
最終ジャッジ日時 2023-10-19 08:57:26
合計ジャッジ時間 5,901 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 352 ms
7,776 KB
testcase_02 AC 339 ms
7,776 KB
testcase_03 AC 340 ms
7,776 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 15 ms
7,616 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 4 ms
4,348 KB
testcase_11 AC 341 ms
7,776 KB
testcase_12 AC 339 ms
7,776 KB
testcase_13 AC 335 ms
7,776 KB
testcase_14 AC 337 ms
7,776 KB
testcase_15 AC 343 ms
7,776 KB
testcase_16 AC 341 ms
7,776 KB
testcase_17 AC 339 ms
7,776 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 base1 = 29;
	ll M = 1000000007;
	for(int num = 1;num <= min(10LL,(ll)s.size());num++){
		ll h1 = 0;
		ll pow = 1;
		for(ll k = num-1;k>=0;k--){
			h1 = (h1+(s[k]-'A')*pow%M)%M;
			pow = (pow*base1)%M;
		}
		table[num].pb(h1);
		for(int i = 1;i <= (ll)s.size()-num;i++){
			ll h2 = table[num][i-1];
			h2 = (h2*base1%M-(s[i-1]-'A')*pow%M+(s[i+num-1]-'A')+M)%M;
			table[num].pb(h2);
		}
	}

	ll cnt = 0;
	rep(i,m){
		ll n = c[i].size();
		ll h1 = 0;
		ll pow = 1;
		for(ll k = n-1;k>=0;k--){
			h1 = (h1+(c[i][k]-'A')*pow%M)%M;
			pow = (pow*base1)%M;
		}
		rep(j,table[n].size()){
			if(table[n][j] == h1)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