結果

問題 No.430 文字列検索
ユーザー pazzle1230pazzle1230
提出日時 2017-09-09 12:11:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 244 ms / 2,000 ms
コード長 1,527 bytes
コンパイル時間 982 ms
コンパイル使用メモリ 103,016 KB
実行使用メモリ 27,136 KB
最終ジャッジ日時 2024-04-24 23:50:55
合計ジャッジ時間 2,481 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,120 KB
testcase_01 AC 244 ms
27,136 KB
testcase_02 AC 7 ms
5,376 KB
testcase_03 AC 8 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 240 ms
26,752 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 14 ms
5,888 KB
testcase_11 AC 70 ms
8,192 KB
testcase_12 AC 70 ms
8,192 KB
testcase_13 AC 70 ms
8,064 KB
testcase_14 AC 53 ms
6,528 KB
testcase_15 AC 41 ms
5,632 KB
testcase_16 AC 12 ms
5,376 KB
testcase_17 AC 10 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

struct RollingHash{
  typedef unsigned long long ull;
  string S;
  ull B;
  vector<ull> hash,p;
  int len;
  RollingHash(){}
  RollingHash(string S,ull B=1000000007LL):S(S),B(B){init();};
  void init(){
    len=S.length();
    hash.resize(len+1);
    p.resize(len+1);
    hash[0]=0;p[0]=1;
    for(int i=0;i<len;i++){
      hash[i+1]=hash[i]*B+S[i];
      p[i+1]=p[i]*B;
    }
  }
  //S[l,r)
  ull find(int l,int r){
    return hash[r]-hash[l]*p[r-l];
  }
};

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	map<unsigned long long, int> mp;
	string s;
	int m;
	cin >> s;
	cin >> m;
	RollingHash rh(s);
	REP(i, s.size()){
		for(int j = 0;j < 10 && i-j >= 0;j++){
			mp[rh.find(i-j, i+1)]++;
		}
	}
	int res = 0;
	REP(i, m){
		string a;
		cin >> a;
		RollingHash c(a);
		res += mp[c.find(0, a.size())];
	}
	cout << res << endl;
	
}
0