結果
| 問題 | No.430 文字列検索 | 
| コンテスト | |
| ユーザー |  kurenai3110 | 
| 提出日時 | 2016-10-03 01:54:38 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 898 bytes | 
| コンパイル時間 | 808 ms | 
| コンパイル使用メモリ | 76,712 KB | 
| 実行使用メモリ | 10,496 KB | 
| 最終ジャッジ日時 | 2024-11-10 00:08:01 | 
| 合計ジャッジ時間 | 3,997 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | -- * 4 | 
| other | AC * 1 TLE * 1 -- * 12 | 
ソースコード
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int m; cin >> m;
	int ans = 0;
	for (int i = 0; i < m; i++) {
		string target; cin >> target;
		if (target.size() > s.size())continue;
		long long hash = 0,target_hash=0;
		for (int j = 0; j < target.size(); j++) target_hash += (target[j] - 'A')*pow(26, j);
		for (int j = 0; j < target.size(); j++) hash += (s[j] - 'A')*pow(26, j);
		if (hash == target_hash)ans++;
			//cout << target_hash << endl;
			//cout << target_hash << endl;
		for (int j = target.size(); j < s.size(); j++) {
			hash -= s[j - target.size()] - 'A';
			hash /= 26;
			hash += (s[j] - 'A')*pow(26, target.size() - 1);
			if (hash == target_hash)ans++;
			//cout << hash << endl;
		}
	}
	cout << ans << endl;
	return 0;
}
            
            
            
        