結果
| 問題 | No.430 文字列検索 | 
| コンテスト | |
| ユーザー |  AC2K | 
| 提出日時 | 2022-12-01 17:39:24 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 2,164 bytes | 
| コンパイル時間 | 1,705 ms | 
| コンパイル使用メモリ | 171,788 KB | 
| 実行使用メモリ | 10,656 KB | 
| 最終ジャッジ日時 | 2024-11-10 01:02:34 | 
| 合計ジャッジ時間 | 4,839 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | -- * 4 | 
| other | AC * 1 TLE * 1 -- * 12 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
//#include<atcoder/all>
//using namespace atcoder;
//cout << fixed << setprecision(10);
#define rep(i, N)  for(int i=0;i<(N);i++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using P = pair<int, int>;
const int INF = 1e9;
const ll INFL = 1e18;
const ll MOD = 1e9 + 7;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };
class Hash {
private:
    /*メンバ*/
    ll mod = 998244353;
    ll base = 32;
    string s;
    vector<ll> hash;
    /*modint関連のメソッドを持っておく*/
    ll mod_pow(ll base, ll exp)
    {
        if (exp == 0)
            return 1;
        if (exp == 1)
            return base % mod;
        ll half = mod_pow(base, exp / 2);
        ll ret = (half * half) % mod;
        if (exp % 2 == 1)
            ret = ret * base % mod;
        return ret;
    }
    int id(char c) { return c - 'a' + 1; }
public:
    /*コンストラクタ*/
    Hash(string _s, ll _mod = 998244353, ll _base = 100) :s(_s), mod(_mod), base(_base), hash(_s.size() + 1) {    }
    /*メソッド*/
    /*ハッシュの表を作る*/
    void build() {
        hash[0] = 0;
        for (int i = 0; i < s.size(); i++) {
            hash[i + 1] = (hash[i] * base % mod + id(s[i]) % mod) % mod;
        }
    }
    /*区間ハッシュを求める*/
    ll rangeHash(int l,int r) {
        return (hash[r] - mod_pow(base, r - l + 1) * hash[l - 1] % mod + mod) % mod;    //hash[l,r]=hash[r]-base^(r-l+1)*hash[l-1]
    }
    bool same(int l, int r, int L, int R) {
        bool check = (rangeHash(l, r) == rangeHash(L, R));
        return check;
    }
};
int main() {
    string S;
    cin >> S;
    Hash S1(S);
    S1.build();
    int M;
    cin >> M;
    int ans = 0;
    while (M--) {
        string c;
        cin >> c;
        int siz = c.size();
        Hash S2(c);
        S2.build();
        ll val2 = S2.rangeHash(1, siz);
        for (int i = 1; i + siz - 1 <= S.size(); i++) {
            ll val = S1.rangeHash(i, i + siz - 1);
            if (val == val2)ans++;
        }
    }
    cout << ans << endl;
}
            
            
            
        