結果
| 問題 | No.430 文字列検索 | 
| コンテスト | |
| ユーザー |  Yut176 | 
| 提出日時 | 2016-10-02 23:56:57 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 438 ms / 2,000 ms | 
| コード長 | 668 bytes | 
| コンパイル時間 | 459 ms | 
| コンパイル使用メモリ | 66,704 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-10 00:05:35 | 
| 合計ジャッジ時間 | 5,341 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 14 | 
ソースコード
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	string s;
	cin >> s;
	int m;
	cin >> m;
	vector<string> c(m);
	for(int i=0; i<m; i++) cin >> c[i];
	int cnt = 0;
	long long int b = 100000007;
	for(int i=0; i<m; i++){
		long long int t = 1;
		for(int j=0; j<c[i].size(); j++) t *= b;
		long long int x=0, y=0;
		for(int j=0; j<c[i].size(); j++){
			x = x*b + c[i][j];
			y = y*b + s[j];
		}
		for(int j=0; j+c[i].size()<=s.size(); j++){
			if( x == y ) cnt++;
			if( j + c[i].size() < s.size() ) y = y*b + s[ j+c[i].size() ] - s[j] * t;
		}
	} 
	cout << cnt << endl;
	return 0;
}
            
            
            
        