結果

問題 No.430 文字列検索
ユーザー alorie10
提出日時 2020-11-17 21:12:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 855 bytes
コンパイル時間 2,153 ms
コンパイル使用メモリ 196,836 KB
最終ジャッジ日時 2025-01-16 01:25:51
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 10 TLE * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
vector<int> table,res;
int n;
string s,t;
vector<int> pre_kmp(string s){
    vector<int> v(s.size()+1);
    int k;
    v[0]=-1;
    for(int i=1;i<=s.size();i++){
        k=v[i-1];
        while(k>=0){
            if(s[k]==s[i-1])break;
            else k=v[k];
        }
        v[i]=k+1;
    }
    return v;
}
void match(string s, string t){
    int head = 0, j = 0, slen=s.size(),tlen=t.size();
    while(head + j < slen){
        if(t[j] == s[head + j]){
            if(++j != tlen) continue;
            res.push_back(head);
        }
        head += j - table[j], j = max(table[j], 0);
    }
}
int main(void){
    cin>>s>>n;
    for(int i=0;i<n;i++){
        cin>>t;
        table=pre_kmp(t);
        match(s,t);
    }
    //for(auto x:res)cout<<x<<endl;
    cout<<res.size()<<endl;
}
0