結果

問題 No.430 文字列検索
ユーザー gyouzasushigyouzasushi
提出日時 2019-12-01 01:33:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,005 bytes
コンパイル時間 2,132 ms
コンパイル使用メモリ 181,884 KB
実行使用メモリ 28,032 KB
最終ジャッジ日時 2024-05-01 03:35:36
合計ジャッジ時間 4,085 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 WA -
testcase_02 AC 32 ms
6,944 KB
testcase_03 AC 34 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 395 ms
27,904 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 18 ms
6,940 KB
testcase_11 AC 95 ms
8,960 KB
testcase_12 AC 90 ms
8,960 KB
testcase_13 AC 91 ms
8,832 KB
testcase_14 AC 77 ms
7,424 KB
testcase_15 AC 64 ms
6,940 KB
testcase_16 AC 37 ms
6,944 KB
testcase_17 AC 36 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

struct RollingHash {
    int n;
    vector<pair<ll,ll>> vec,pw;
    ll mod1,mod2,base1,base2;
    
    RollingHash(string s) {
        srand(time(NULL));
        n=sz(s);
        vec.resize(n+1);
        pw.resize(n+1);
        pw[0]={1,1};
        
        mod1=1e9+93;
        mod2=1e9+97;
        base1=(ll)rand()%((ll)1e7+9);
        base2=(ll)rand()%((ll)1e7+9);
        rep(i,n) {
            pw[i+1].first=pw[i].first*base1%mod1;
            pw[i+1].second=pw[i].second*base2%mod2;
            vec[i+1].first=(vec[i].first*base1+(ll)s[i])%mod1;
            vec[i+1].second=(vec[i].second*base2+(ll)s[i])%mod2;
        }
    }
    
    //[l,r)
    pair<ll,ll> get(int l,int r) {
        ll fi,se=0;
        fi=(vec[r].first-vec[l].first*pw[r-l].first+mod1*mod1)%mod1;
        se=(vec[r].second-vec[l].second*pw[r-l].second+mod1*mod2)%mod2;
        return make_pair(fi,se);
    }
};

int main() {
    string s;
    cin>>s;
    int n=sz(s);
    RollingHash rlh(s);
    map<pair<ll,ll>,int> mp;
    FOR(len,1,10) {
        rep(i,n-len+1) mp[rlh.get(i,i+len)]++;
    }
    
    int m;
    cin>>m;
    int ans=0;
    while(m--) {
        string t;
        cin>>t;
        RollingHash rlh2(t);
        ans+=mp[rlh2.get(0,sz(t))];
    }
    cout<<ans<<endl;
}
0